Forums Register Login

invoke a java function onSubmit of the form

+Pie Number of slices to send: Send
I have a JSP page with a form inside of it. 'onSubmit' of the form, I want to invoke a java function with a value of the form.
I am adding part of my code here:

<form action="www.yahoo.com" id="hiddenform" name="hiddenform" method="post" onSubmit="<%getResponseValue(out.println("><script>this.ResponseType.value</script>"));%>">

<select name="ResponseType">
<option value="Default">Default</option>
<option value="Sucess">Sucess</option>
<option value="Failure">Failure</option>
<option value="Retry">Retry</option>
</select>
</form>

And here is my java function in the same file:

<%!String getResponseValue(String responseVal){
System.out.println("this is the responsevalue"+responseVal);
return responseVal;
}%>



Could you please let me know, why I am getting an error like below:
'void' type not allowed here
getResponseValue(out.println("<script>this.ResponseType.value</script>")); //[ /Admin.jsp; Line: 49]
^
1 error

+Pie Number of slices to send: Send
Look like you're confusing Javascript with Java.

First step is to stop using scriptlets. It would only increase the confusion. Write raw Java code in Java classes (e.g. servlets, javabeans, dao classes, etc) and use taglibs/EL to control the presentation flow.

Second step is to learn Javascript/HTML DOM properly. There are good tutorials available at w3schools.com.

Just keep this in mind: Java/JSP runs at the server machine and produces a HTML/CSS/JS page, which is been sent from server machine to client machine, in the client machine the webbrowser will start to display HTML/CSS and run JS. Do a 'view source' in your webbrowser, you'll notice that there is no means of JSP/Java. All the HTML event handlers (the on* attributes) are only capable of running JS.
+Pie Number of slices to send: Send
This article should be helpful in understanding why what you are trying to do makes no sense.
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 5081 times.
Similar Threads
Access Data from Database By Submitting The select Values
New Option with CSS...Possible???
How to perform operations like insert,delete,add,move next etc in jsp page?
JavaScript not loading
JSP attendance management project error
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:22:05.