0

Dear All,

I'm working on a web application, JSP. I have a script with a javascript function that returns a String. I want this returned String to be passed to another page in a form, when a button is clicked.

Any ideas on how to make this work?

I was thinking of something like:

<form action="nextPage.jsp" method="post   ">
 <input type="button" value="button"  onClick="calledFunction();">                        <input type="hidden" name="varname"  value="calledFunction();" />
 </form>

and then I would call in the nextpage.jsp:

<% out.println(request.getParameter("varname"));%>

But it doesn't work, the output I get is the function name and not the returned value.

Could you help me?

2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by softDeveloper
0

The line

<input type="hidden" name="varname"  value="calledFunction();" />

does not assign the value returned from the javascript function to 'varname' but assign the value 'calledFunction();'. Hence you are getting the function name in your jsp. You will have to assign the value to 'varname' at the onclick event of the button using javascript

Try this code snippet

<form name="form1" action="nextPage.jsp" method="post ">
    <input type="button" value="button" onClick="document.form1.varname.value = calledFunction();"> 
    <input type="hidden" name="varname" value="" />
</form>

Hope it helps

0

The line

<input type="hidden" name="varname"  value="calledFunction();" />

does not assign the value returned from the javascript function to 'varname' but assign the value 'calledFunction();'. Hence you are getting the function name in your jsp. You will have to assign the value to 'varname' at the onclick event of the button using javascript

Try this code snippet

<form name="form1" action="nextPage.jsp" method="post ">
    <input type="button" value="button" onClick="document.form1.varname.value = calledFunction();"> 
    <input type="hidden" name="varname" value="" />
</form>

Hope it helps

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.