• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaScript and JSP

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic