[Logo]
Forums Register Login
invoke a java function onSubmit of the form
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

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.
This article should be helpful in understanding why what you are trying to do makes no sense.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 17, 2017 16:21:52.