Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript/jsp

 
Peter Guillebaud
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to get a javascript onClick() event to fire a sql query from my jsp page?
 
Gurpreet Sachdeva
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Peter,
First I would say why you want to use JavaScript, why not jsp at both pages.
Okay, here is your solution........
HTML file using java script.

JSP file for firing SQL query.

This is just a sample code.You can modify it according to your requirment.
------------------
Regards
Gurpreet Sachdeva
For Mock Exams, FAQ, Exam tips and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: http://www.go4java.lookscool.com
[This message has been edited by Gurpreet Sachdeva (edited October 26, 2001).]
 
Peter Guillebaud
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gurpreet,
What I am trying to do is have one html select box populated as a result of a choice from a previous select box. I want to avoid having submit buttons but to use the onChange() method of the select box. What needs to happen is when the user chooses a value from the first box, the onChange() event on the client side somehow fires a sql query which populates the second box according to the choice in the first. Any ideas welcome!
TIA
[This message has been edited by Peter Guillebaud (edited October 29, 2001).]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, just remember that javascript is 100% client-side, and JSP code is 100% server-side.

There is really no way to get JSP code to run, and return to the 'same' page on the client side. You'll need a re-load of some sort. You *can* use javascript to submit the page to your server-side code, be it a JSP (and of course, you can submit the page to itself) or servlet. The server-side will know which value in the first select box has been selected, and when it is finished, it will re-display with both select boxes full of values.
 
Peter Guillebaud
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Mike, I used javascript to resubmit the jsp page to itself when the onchange() event was fired in the select box, and then jsp to do the sql query. Thanks for your help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic