File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript and JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript and JSP" Watch "JavaScript and JSP" New topic
Author

JavaScript and JSP

arpit singla
Ranch Hand

Joined: Jun 18, 2001
Posts: 66
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

Joined: Feb 22, 2001
Posts: 73
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaScript and JSP
 
Similar Threads
Form is submitting more than once
Struts with Javascript problem
creating button using <s:button> - similar to the CSS based button
JSP with embedded javascript
How to refresh page only once automatically when page is loaded