1

Hi i want to change the path of the URL when the drop-down box is changed on my page.

<select id="SelectLocation" class="large" data-bind="value: StoreLocationSelected" >
<option value="0" label="choose one"></option>
<option>1</option>
<option>1</option>
<option>1</option>
<option>1</option> 
</select>

When the option is changed on the drop-down i want the page to re-load with the relevant URL path i have asked it to. Any suggestions?

Thanks

5 Answers 5

2

You can use the below approach.

<select id="dynamic_select">
    <option value="" selected>Pick a Website</option>
    <option value="http://www.google.com/">Google</option>
    <option value="http://www.youtube.com/">YouTube</option>
    <option value="http://www.stackoverflow.com/">Stack Overflow</option>
</select>

<script>
    $(function(){
      // bind change event to select
      $('#dynamic_select').bind('change', function () {
          var url = $(this).val(); // get selected value
          if (url) { // require a URL
              window.location = url; // redirect
          }
          return false;
      });
    });
</script>

Fiddle: http://jsfiddle.net/kiranvarthi/z60sxfkd/

Sign up to request clarification or add additional context in comments.

Comments

0

Try something like

<select id="SelectLocation" class="large" data-bind="value: G4.Model.Ticketing.StoreLocationSelected" onchange="window.location.href = 'Here get right url depending on value';" >
<option value="0" label="choose one"></option>
<option>1</option>
<option>1</option>
<option>1</option>
<option>1</option>
</select>

Comments

0

Use This

   location.href="Your dropdown ITEM"   // Set this with your js function, onclick or whatever the way u want.

Comments

0

Something like this:

$("#SelectLocation").on("change", function(){
    document.location.href = $(this).val(); //assuming options have urls's in them
});

Comments

0

Not sure whether I got your question correctly or not. I think you want to post back to the server. If you want to change form url then you can use javascript/jquery and then do a submit with all the form data.

//by name
document.myform.action = url;

//by id
document.getElementById("form_id").action = url;
document.getElementById("form_id").submit();

//jquery
$("#form_id").attr("action", url);
$("#form_id")[0].submit();

You can use drop downs selected index changed event to execute your JS.

Check the URL below for more information: http://www.web-source.net/web_development/form_action.htm#.VEjMgyKUdDQ

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.