Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript and JSP

 
arpit singla
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 problems:
1. I am embedding JavaScript in JSP to check the value of a text box as following :
function Check()
{
var n =<%= Integer.parseInt((String)request.getAttribute("quantity"))%>
if(1 > n > 20)
alert(" Please enter valid number");
}
please let me know if this is the right way to embed the javascript.. and do java code need to be in <% --code-- %> in the aboce script. help would be greately appreciated.
2. when i click on the refresh button on the browser, it submits the form again. Is there a way so that form is not submitted on clicking refresh button.
looking forward to your help. .thanks
 
Connie Boyd
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But then what is calling your function? Is there a reason you are not using plain javascript with the HTML form? Why not check the value of "quantity" before you process the page? You can use onSubmit or onClick with your form to check the value before submission.
As far as refreshing the page, if your page has already been submitted and what you are looking at is the results after returning from form processing, you are always going to resubmit the form on refresh. You'd have to use your back button to get back to the original form. Does that make sense or sound like babbling?
I hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic