• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getParameter() and JavaScript

 
Jolly Khanna
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my jsp page, I'm setting the value of a hidden textbox and I'm trying to retrieve the contents of that text box in a Servlet using request.getParamter, but I'm getting "null" as a result. First I set the value of the hidden paramter in javascript. I don't use an "action" for my form. Instead I use location.href in javascript. Can someone PLEASE help?
Here is the JSP page:
<Javascript>
function setValue(str1, str2)
{
document.test.name.value = str2
document.test.submit();
location.href = "/myPage/" + str1;
}
</javascript >
<form name="test"><input type=hidden name="name" value="">
</form >
<a on_click = "setValue('Hello', 'World');" Click me!</a >
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Jolly, I'm not sure how the Request.getParameter() fits into all this since you mention it in your message, but do not reference it anywhere in your example code. But, I think the javascript you want is more along the lines of:

This probably should be moved to the Javascript forum.
hth,
bear
 
Jolly Khanna
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Bear,
Thanks for your help.
The request.getParameter() was being used to set the value of "name" to an object. In my Servlet I was calling String name = request.getParameter("name"); but the value was coming up null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic