Results 1 to 10 of 10

Thread: How do I pass a value from a dropdownlistbox to a new page?

  1. #1
    Guest
    I have defined a dropdownlistbox (let's say I named it "MyDropDownListBox") on one page. Now when I select a value from that listbox, I want to jump to another page, passing the selected value (an ID) along in the querystring.

    How do I make it do that?

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    try this:

    Code:
    <html>
    <head></head>
    <body>
    <form name=frm3 action=some.asp>
    	<select name=select1 onClick="document.frm3.submit()">
    		<option value="Option 1">Option 1</option>
    		<option value="Option 2">Option 2</option>
    		<option value="Option 3">Option 3</option>
    	</select>
    </form>
    </body>
    </html>
    some.asp
    Code:
    <%@ Language=VBScript %>
    <HTML>
    <HEAD>
    
    </HEAD>
    <BODY>
    
    <h1>some asp</h1>
    <%
    response.write("select 1: " & request("select1") & "<BR>")
    
    %>
    
    
    </BODY>
    </HTML>
    Mark
    -------------------

  3. #3
    Guest
    Okay, this works... almost.

    Now when I release my mousebutton (after clicking it) on the arrow of the dropdownlistbox, it refreshes the page immediately (it redirects to itself). If I want to select a user, I have to hold the button down. This is not how a dropdownlistbox usually works, is it?

    Now I don't want the page to refresh untill I select a user from the dropdownlist, not as soon as I have clicked the dropdownlistbox-arrow.

    And I would also like the selected user to still be selected after refreshing the page. How do I do that?

    Thanx a lot.

    [Edited by MarcelB on 10-30-2000 at 10:02 AM]

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    try this:

    the doit() function makes sure the page is not submitted when the arrow is first clicked.

    keeping the option selected:
    there's lots of different ways to do this

    if the value of the options are numeric it's a bit easier see select2


    Code:
    <%@ Language=VBScript %>
    <HTML>
    <HEAD>
    <script language=javascript>
    var clickCount = 0;
    function doit()
    {
    	if(clickCount==0)
    	{
    	clickCount++;
    	}else{
    		document.frm3.submit()
    	}
    
    }
    </script>
    </HEAD>
    
    <%
    dim opt
    dim opt2
    
    opt = request("select1") 
    opt2 = cint(request("select2"))
    %>
    
    <BODY>
    <form name=frm3 action=some.asp>
    <select name=select1 onclick='doit()'>
    
    <%
    select case  opt
    	case "Option 2"
    		response.write "<option value='Option 1'>Option 1</option>" & vbcrlf
    		response.write "<option value='Option 2' selected>Option 2</option>" & vbcrlf
    		response.write "<option value='Option 3'>Option 3</option>" & vbcrlf
    	case "Option 3"
    		response.write "<option value='Option 1'>Option 1</option>" & vbcrlf
    		response.write "<option value='Option 2'>Option 2</option>" & vbcrlf 
    		response.write "<option value='Option 3' selected>Option 3</option>" & vbcrlf 
    	case else
    		response.write "<option value='Option 1' selected>Option 1</option>" & vbcrlf 
    		response.write "<option value='Option 2'>Option 2</option>" & vbcrlf
    		response.write "<option value='Option 3'>Option 3</option>" & vbcrlf 
    end select
    %>
    </select>
    
    
    <select name=select2 onclick='doit()'>
    	<option value=0>Option 1</option>
    	<option value=1>Option 2</option>
    	<option value=2>Option 3</option>
    </select>
    </form>
    
    <%
    response.write "<script language=javascript>" & vbcrlf
    response.write "document.frm3.select2.selectedIndex=" & opt2 & ";" & vbcrlf
    response.write "</script>" & vbcrlf 
    
    %>
    
    
    </body>
    </html>
    Mark
    -------------------

  5. #5
    Guest
    Okay, getting closer.. but not yet exactly what I want. (sorry)

    Now when a user clicks the arrow, then for some reason clicks it again without having selected an option, it still refreshes the page, which is not what I want. I know this was somewhat of a dirty work-around way (no offense) to solve the problem, but surely there must be a "clean" way too, right? Anyone?

    Furthermore in the select box, I have a UserID and a name, where the index in the combobox does not necessarily match the ID of the user. Now when the admin selects the user with UserID = 3, it selects the third user in the dropdownlistbox, instead of the user with UserID = 3.

    I also tried the other method (using a variant of the case statement) but that didn't seem to work either. Any other ideas?

    Thanx a lot for thinking along, by the way. I really appreciate it.

  6. #6
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Try using the onchange event instead. Have the first option in your select tag be a dummy option that just says "Please select..." or something like that. In your onchange event, do your refresh only if that is not the selected index.

    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    monte96_@hotmail.com
    monte96@vbgarage.com


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  7. #7
    Guest
    Alrighty! Thanx again, Monty.. once again, you save the day!

    BUT...... that still leaves me with the problem of having the right option selected after refreshing the page.
    Is there some way I could read the index of the selected option instead of the value? Then if I pass that index along, and after the refresh I build the dropdownlistbox the same way I built it before the refresh, the index should point to the selected user, right?

  8. #8
    Guest
    Alrighty!!!!

    I got that last thing to work aswell, thanx to Mark. I had converted the UserID that I got from the database to an integer, but I hadn't converted the value that was passed along to an integer, so when I compared the two, they weren't the same.

    Thanx guys, you're the best!

  9. #9
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    It's a tad tricky trying to visualise what you want to do!

    what you could do is have the data (could do with an example really) in a javascript array and then have numeric option values and then pick out the required element from the array onChange and post it


    Code:
    <%@ Language=VBScript %>
    <html>
    <head>
    
    <%
    dim opt
    dim choice
    
    opt = cint(request("select1"))
    choice= request("SelectedOption")
    
    %>
    <script language=javascript>
    var anArray = new Array();
    anArray[0] = "Please select";
    anArray[1] = "Option 1";
    anArray[2] = "Option 2";
    anArray[3] = "Option 3";
    
    function doit(v)
    {
    	document.frm3.SelectedOption.value = anArray[v];
    	document.frm3.submit();
    }
    
    
    </script>
    </head>
    
    <body onLoad="document.frm3.select1.selectedIndex=<%=opt%>;">
    
    <form name=frm3 action=some.asp>
    	<select name=select1 onChange="doit(this.selectedIndex);">
    	<option value="0">Please select</option>
    	<option value="1">Option 1</option>
    	<option value="2">Option 2</option>
    	<option value="3">Option 3</option>
    	</select>
    	<input type=hidden name=SelectedOption>
    </form>
    
    <%
    Response.Write "you chose " & choice
    %>
    
    </body>
    
    </html>
    Mark
    -------------------

  10. #10
    Guest
    Actually I "already" have it working, Mark, thanx to you and Monty's combined effort.
    But thanx for replying anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width