[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2161
  • Last Modified:

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

0
sureshraina
Asked:
sureshraina
  • 2
  • 2
  • 2
  • +1
1 Solution
 
sforcierCommented:
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>
0
 
sureshrainaAuthor Commented:
thanks.

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

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

                  parent.window.location.href = 'http://example.com/foo.aspx?cid=' + obj.options[obj.selectedIndex].value;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sureshrainaAuthor Commented:
It is still opening in new window after changing.

I cannot submit the form as i am doing other things on submit
0
 
RejojohnyCommented:
remember u are using ASP.Net and no more coding in ASP .. so try to use its inbuild functionalities wherever possible. ...

so use a web control and instead of a HTML control ..
i.e. a "dropdownlist" control instead of the HTML "select" tag ..
set the "Autopostback" property of the "dropdownlist" to "true" ...

then in the "selectedindexchanged" event of the dropdownlist ..
write the code

response.redirect "abs.aspx?cid=" & dropdownlist1.selectedValue

Rejo
0
 
GRCHELPDESKCommented:
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>")
0
 
RejojohnyCommented:
just curious, any particular reason for a grade B?
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now