Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

invoke a java function onSubmit of the form

 
patt rich
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article should be helpful in understanding why what you are trying to do makes no sense.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!