A servlet passes parameters to a jsp. this jsp is using javascript. there is a button in this jsp "Evaluate" which when clicked i want to update the grandtotal.but when i click the button, gives me nullpointer exception because values passed from servlet are null. I dont know when i click Evaluate, why it gets the parameters from servlet again. i am not even submitting the form again. my jsp: <html> <head> <title> Check Out</title> <script language="JavaScript"> function mode(field) { var val = field.value; document.write(val); } </script> </head> <body> <% // code for getting values from Servlet %> <form name="chkout"> <table> <tr> <input type="radio" name="Overnight" value="overnight"> Overnight<br> <input type="radio" name="Overnight" value="snail"> 3-5 days<br> <input type="submit" name="evaluate" value="Evaluate" onClick="mode(Overnight)"> </td> </tr> </table> </form> </body> </html> if sb. could tell me what i am doing wrong and if could suggest me a right way to do it... thanks a lot in advance.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
1
posted
0
I think the first step would be to examine the generated HTML to see if the values are really there. Do you have a prototype in plain HTML that works correctly? Bill
--------------------- class chkoutServlet{ ..... .... public void service(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException{ ...... String overnight=request.getParameter("Overnight"); String snail=request.getParameter("Snail"); ...... }
} If I have done wrongly...I am very sorry and correct me
Dil se....,<BR>Dayanand<BR>0065-8839071(off)<BR>0065-7547034(Res0
arpit singla
Ranch Hand
Joined: Jun 18, 2001
Posts: 66
posted
0
dayanand, Bill thanks for responding.. i found out that when i click "Evaluate" button, form is being submitted which i dont want. So I made Evaluate a simple button which calls a javascript.
now when i click Evaluate button, i want to know which radio field was selected, thats why I kept the name of both radio same.
now problem is : document.myform.Overnight.value; does not seem to return anything....... my javascript function is : function mode() { var test = document.myform.Overnight.value; if( test == "overnight") { alert('overnight'); } else if( test == "snail") { alert('snail'); }
} i donot get the alerts when any of the radio is selected.. please let me know the reason.. thanks to you all.
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
posted
0
For radio buttons and checkboxes, you want to check the "checked" state. if(yourControlName.checked) doWhatEver....
Bosun
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
arpit singla
Ranch Hand
Joined: Jun 18, 2001
Posts: 66
posted
0
bosun how do i retrieve the value of the checkbox. I have following 2 checkboxes: <input type="radio" name="Overnight" value="overnight"> Overnight<br> <input type="radio" name="Overnight" value="snail"> 3-5 days<br> document.myform.Overnight.checked, will let me know that checkbox is selected but wouldn't tell me which checkbox ?? how can i detemine which checkbox is selected ? thanks
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.