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....

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

ya right....but can u please help a lil bit with the code

<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;
             
             
          }

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

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")

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

if(request.getParameter("distselect")!=null && issubmitted!=true)
//sm stuff
else
//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!

First of all if you want the initial data to be displayed then maybe you can do something like this:

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

This article has been dead for over six months. Start a new discussion instead.