Link to home
Start Free TrialLog in
Avatar of sureshraina
sureshraina

asked on

onchange redirect

I have a <select id=aid >
<option=1>US</option>
<option=2>UK</option>
</select> element in my abs.aspx page.

I want to redirect the user onchange of selectbox to the same page and pass a parameter cid which will be the selected value.

i.e if user selects UK it should redirect to abs.aspx?cid=2

Pls help

Avatar of sforcier
sforcier

The following Javascript implementation should work (NOTE: you have a syntax error on your option tags, which is corrected below):

<script>
            function cboChange(obj)
            {
                  window.location.href = 'http://example.com/foo.aspx?cid=' + obj.options[obj.selectedIndex].value;
            }
</script>

<select id="aid" onchange="cboChange(this);" >
      <option value="1">US</option>
      <option value="2">UK</option>
</select>
Avatar of sureshraina

ASKER

thanks.

But this is opening in a new window. I want in the same window..

thanks again
ok, change the line with window.location.href to:

                  parent.window.location.href = 'http://example.com/foo.aspx?cid=' + obj.options[obj.selectedIndex].value;
It is still opening in new window after changing.

I cannot submit the form as i am doing other things on submit
ASKER CERTIFIED SOLUTION
Avatar of Rejojohny
Rejojohny
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This might work as well.  Replace 'ddlName' with the name of your Drop Down List control.

Response.Write("<script>window.open(abs.aspx?cid=" & ddlName.SelectedValue &  "');</script>")
just curious, any particular reason for a grade B?