Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

onchange on combobox

Posted on 2004-10-29
7
Medium Priority
?
11,484 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
Comment
Question by:widiyanto
  • 3
  • 3
7 Comments
 
LVL 12

Expert Comment

by:minichicken
ID: 12442608
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
ID: 12442640
thanks for the quick response.. but I'm using jsp.. :D
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12442653
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:steve_bagnall
ID: 12443027
Hi,

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

request.getParameter("select");

Cheers, Steve
0
 

Author Comment

by:widiyanto
ID: 12450023
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:
minichicken earned 400 total points
ID: 12450988
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
ID: 12459997
ok.. Thanks...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
Suggested Courses

916 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