Solved

onchange on combobox

Posted on 2004-10-29
11,428 Views
Last Modified: 2008-03-04
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
Question by:widiyanto
    7 Comments
     
    LVL 12

    Expert Comment

    by:minichicken
    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
     

    Author Comment

    by:widiyanto
    thanks for the quick response.. but I'm using jsp.. :D
    0
     
    LVL 12

    Expert Comment

    by:minichicken
    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
     
    LVL 5

    Expert Comment

    by:steve_bagnall
    Hi,

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

    request.getParameter("select");

    Cheers, Steve
    0
     

    Author Comment

    by:widiyanto
    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
     
    LVL 12

    Accepted Solution

    by:
    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
     

    Author Comment

    by:widiyanto
    ok.. Thanks...
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now