aspose file tools*
The moose likes Servlets and the fly likes JSP with embedded javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP with embedded javascript" Watch "JSP with embedded javascript" New topic
Author

JSP with embedded javascript

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");
}
<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

Joined: Jul 26, 2001
Posts: 170
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


<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP with embedded javascript
 
Similar Threads
JavaScript and JSP
Javascript
Struts with Javascript problem
How to refresh page only once automatically when page is loaded
I know what to do but don't know how to implement it..