Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I call a javascript function from a jsp page. 1

Status
Not open for further replies.

FreshmenProgrammer

Programmer
Jan 16, 2006
42
0
0
CA
First off i would like to say thanks for the help!

I was just wondering how I can call a javascript function just from jsp code. for example what line can I put in that code where the **** ***** are.

Thank you

Code:
<script language="javascript">
function setValue(val){
	
	document.myForm.buttonValue.value = val;
}
function closeWin(){
	window.close();
}
</script>

if (buttonValue != null && buttonValue.equals("worked")){
   
   ********** document.closeWin(); *************
}
 
Well, I wouldn't do that personally, because I feel it its a bit messy, but you could do :

Code:
<script language="javascript">
function setValue(val){
    
    document.myForm.buttonValue.value = val;
}
function closeWin(){
    window.close();
}
</script>

<%
if (buttonValue != null && buttonValue.equals("worked")){
%>   
   <script language="javascript">document.closeWin();</script>
<%
}
%>

I think that would do it.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Just think that jsp help you to write a html dynamically.
Let 's say there is a jsp page in and you browse this site with a browser. If you view the source of that page within browser, it is just a html.
Therefore, jsp can do all the stuffs that html can. (Because jsp file will be translated to html when it is run and reach your browser.)

you can write the default value of JavaScript variable with JSP. you can even write JavaScipt dynamically with jsp.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top