Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP with embedded javascript

 
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");
}
<input type="Submit" name="update" value="Update" onClick="Check()">
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
 
Sam Dalton
Author
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This certainly looks like a fine way to embed javascript.
The <%=%> are indeed necessary.
Not sure why your form would be resubmitting on refresh....
S
Originally posted by arpit singla:
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");
}
<input type="Submit" name="update" value="Update" onClick="Check()">
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic