• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 11498
  • Last Modified:

onchange on combobox

Hi,

I would like to ask about the onchange method in javascript.

For example: if there is name combobox in my jsp page, the names inside it are retrieved from database. if I want like if I select 'lala' from combobox then it will display a table of information about 'lala' such as her address and contact no but if I never select anything then it doesn't show the table.

I've manage to find out how to do that by reloading to that page and passing the parameter name so the url is something like this: http://192.168.28.174:8080/TWIS/intranet/sample/showDetail1.jsp?samplecode=lala 

if its empty then it will be like this:
http://192.168.28.174:8080/TWIS/intranet/sample/showDetail1.jsp?samplecode=
which I don't want... I want it to be like this:
http://192.168.28.174:8080/TWIS/intranet/sample/showDetail1.jsp

cos there are a lot of pages that is linked to this page so if I change that it will become more complicated. any ideas how to do that? thanks.

here is my sample code:
<select name="samplecode" size="1" id="select" onchange="location.reload('showDetail1.jsp?samplecode='+this.options[this.selectedIndex].value)">
<option selected><%= request.getParameter("samplecode")%></option>
<option></option>
<%
        conn = db.getConnection();
        stmt = conn.createStatement();
        sql="select sample from sampledefinition";
        rs=stmt.executeQuery(sql);
        while(rs.next()){
%>
       <option value="<%=rs.getString("sample")%>"><%=rs.getString("sample")%></option>
       <%}
            rs.close();
            stmt.close();
            conn.close();
      %>
     </select>
0
widiyanto
Asked:
widiyanto
  • 3
  • 3
1 Solution
 
minichickenCommented:
You can do somoething like this: A form which will submit to it self. and on your ASP page you just use Request.Querystring to get the value.

<form name="form1" method="get" action="">
  <select name="select" onChange="form1.submit()">
    <option>Value1</option>
    <option>Value2</option>
    <option>Value3</option>
  </select>
</form>
0
 
widiyantoAuthor Commented:
thanks for the quick response.. but I'm using jsp.. :D
0
 
minichickenCommented:
Oh sorry, but it will work basically the same way, on your JSP page, use the method to request values from the URL querystring.

<form name="form1" method="get" action="">
  <select name="select" onChange="form1.submit()">
    <option>Value1</option>
    <option>Value2</option>
    <option>Value3</option>
  </select>
</form>
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
steve_bagnallCommented:
Hi,

I think this is what you're looking for..

request.getParameter("select");

Cheers, Steve
0
 
widiyantoAuthor Commented:
ok thanks....
I tried the code and it works... but when I want to link to that page, I got http error--404 eventhough I put the file on the correct page  or sometimes it java nullpointer error... can help me? thanks.
0
 
minichickenCommented:
How about this?

<form name="form1" method="get" action="showDetail1.jsp">
  <select name="select" onChange="form1.submit()">
    <option>Value1</option>
    <option>Value2</option>
    <option>Value3</option>
  </select>
</form>
0
 
widiyantoAuthor Commented:
ok.. Thanks...
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now