execute a java method on change of select option

Reply

Join Date: Jun 2009
Posts: 16
Reputation: memegha123 is an unknown quantity at this point 
Solved Threads: 0
memegha123 memegha123 is offline Offline
Newbie Poster

execute a java method on change of select option

 
0
  #1
Jul 8th, 2009
hi!
I m writing a jsp where i want the page content to change when the selected option from a combo changes...how do i execute the method that determines the code which will fetch that data....i guess i'' have to go with javascript but i dont think a java script func can read a server side file so please help....
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: execute a java method on change of select option

 
0
  #2
Jul 8th, 2009
When the onchange method is called you can submit the form to a servlet. Then read the data and come back to the jsp.
Read the first post at the jsp forum for more details on how to connecti jsp and servlet with database
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 16
Reputation: memegha123 is an unknown quantity at this point 
Solved Threads: 0
memegha123 memegha123 is offline Offline
Newbie Poster

Re: execute a java method on change of select option

 
0
  #3
Jul 8th, 2009
ya right....but can u please help a lil bit with the code
  1.  
  2.  
  3. <select name="Distselect" onChange="distdisplay()" >
  4. <option value="Shimla">Shimla</option>
  5. <option value="Mandi">Mandi</option>
  6. <option value="Kullu">Kullu</option>
  7. <form name="getdist" action="districtdisplay.jsp">
  8. function distdisplay()
  9. {
  10. var dist=document.formname.Distselect.value;
  11.  
  12. document.formname.submit;
  13.  
  14.  
  15. }
these are sum of code snippets i have used n it's working but the problem is i am not able to autosubmit when the select option changes though on clicking submit button i have used i am able to submit the page to a new JSP(districtdisplay.jsp)...
can u help..n also i m reading data from a text file n i want the data on the same page not the redirected jsp page so pls help
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: execute a java method on change of select option

 
0
  #4
Jul 8th, 2009
If you want to call a java method you need to go to the server, so you need to submit.
The "select" part must be inside the form otherwise the what you have selected will not be send at the request.

Just replace this call:
onchange = "distdisplay()"
with the one that submits the form.

Then take the value of what was selected and do your thing:

request,getParameter("Distselect")
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 16
Reputation: memegha123 is an unknown quantity at this point 
Solved Threads: 0
memegha123 memegha123 is offline Offline
Newbie Poster

Re: execute a java method on change of select option

 
0
  #5
Jul 17th, 2009
hi!
thanx for replying i had select in the form tag only and i was submiting the form in distdispaly() method for nw it's running fine except that it does not display my initial data....when the form is displayed first
for which i hav code like i
  1. if(request.getParameter("distselect")!=null && issubmitted!=true)
  2. //sm stuff
  3. else
  4. //my initial data
is submitted is a hidden field to check if the form is submitted or is displayed first...this form submits to itself
secondly....as soon as the page submits the select list selected value becomes the default selected value the first value....
i need it to retain the submitted value....pls help!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: execute a java method on change of select option

 
0
  #6
Jul 18th, 2009
First of all if you want the initial data to be displayed then maybe you can do something like this:

  1. if(request.getParameter("distselect")!=null && issubmitted!=true) {
  2. //sm stuff
  3. }
  4. //else -- remove the else
  5. //my initial data

About the default value at the "select" check this link:

http://www.w3schools.com/tags/att_option_selected.asp

Remember only 1 option can have the "selected" attribute and if more than one have it the default value will the last option that had it.

And I believe that I mentioned that site. Maybe you should read its tutorials because they helped me a lot
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC