| | |
execute a java method on change of select option
![]() |
•
•
Join Date: Jun 2009
Posts: 16
Reputation:
Solved Threads: 0
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....
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....
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
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
•
•
Join Date: Jun 2009
Posts: 16
Reputation:
Solved Threads: 0
ya right....but can u please help a lil bit with the code 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
Java Syntax (Toggle Plain Text)
<select name="Distselect" onChange="distdisplay()" > <option value="Shimla">Shimla</option> <option value="Mandi">Mandi</option> <option value="Kullu">Kullu</option> <form name="getdist" action="districtdisplay.jsp"> function distdisplay() { var dist=document.formname.Distselect.value; document.formname.submit; }
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
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")
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
•
•
Join Date: Jun 2009
Posts: 16
Reputation:
Solved Threads: 0
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 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!
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
Java Syntax (Toggle Plain Text)
if(request.getParameter("distselect")!=null && issubmitted!=true) //sm stuff else //my initial data
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!
First of all if you want the initial data to be displayed then maybe you can do something like this:
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
Java Syntax (Toggle Plain Text)
if(request.getParameter("distselect")!=null && issubmitted!=true) { //sm stuff } //else -- remove the else //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
![]() |
Similar Threads
- Connectin VB6 to mssql and select option button (Visual Basic 4 / 5 / 6)
- retrieve request parameter of 1 frame to another (JSP)
- interesting situation (PHP)
- Extracting select option fields from mySQL (PHP)
- compiling from command line (Java)
- WindowsXP makes me wait! (Windows NT / 2000 / XP)
- HTML Form not working with IE when lots of select/option boxes included. (HTML and CSS)
- HTML Form not working with IE when lots of select/option boxes included. (Web Browsers)
Other Threads in the Java Forum
- Previous Thread: Multiple file read, then write
- Next Thread: what can i use to control temperature in GUI
| Thread Tools | Search this Thread |
account android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner search server set smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree webservices windows






