0

I am using this neat plugin for customising <select> lists.

http://exodecreations.com/jQuery/jqDropDown.html

I am trying to come up with code so that when user selects each option, he is redirected to a page. My code is as follows:

<form action="#">
<select id="elidp" >
<option value='' disabled selected>Choose Location...</option>
<option value='http://www.google.com/'>New York</option>
<option value='http://www.google.com/'>LA</option>
</select>
</form>

Jquery:

jQuery(function() {  

    jQuery('#elidp').jqDropDown({
      optionChanged: function(){ jQuery('#elidp').on('change', function () {var url = $(this).val(); if (url) {window.location = url;}return false;});}, 
        direction: 'up',
        defaultStyle: false,
        containerName: 'theContainer',
        toggleBtnName: 'awesomeToggleClass',
        optionListName: 'thisListIsRocking',
        effect: 'fade',
        effectSpeed: 300
    });

}); 

However, nothing happens when user changes options... Any ideas?

4
  • Have you looked at the javascript console of your browser for any possible errors ?
    – Tito
    Commented Jul 21, 2013 at 18:32
  • Whatever value you assign to those options like 'optionChanged' is the code that will be triggered on the select change. Instead of triggering the code you actually wanted to execute, you were instead binding an event handler to the select 'change' event. By the time that was bound, the change had already occurred (that's why the code ran in the first place).
    – p e p
    Commented Jul 21, 2013 at 18:33
  • thanks but there seems to be another problem - the HTML markup is rendered like this: <li class="ddOption"><a class="" href="#" rel="http://www.google.com/">New York</a></li>
    – JoaMika
    Commented Jul 21, 2013 at 18:44
  • how can i pass the select list option value to the href element ?
    – JoaMika
    Commented Jul 21, 2013 at 18:45

2 Answers 2

1

Because they don't actually change. The value of two options provided is the same (google.com)

0

The optionChanged method of jqDropDown is handling the onChange event of the select element. Attaching an additional event handler with the .on jQuery method is not what you want to do.

  optionChanged: function(){ 
      jQuery('#elidp').on('change', function () {
          var url = $(this).val(); 
          if (url) {window.location = url;}
          return false;
      });
  }

Should be something more like this:

  optionChanged: function(){ 
      var url = $(this).val(); 
      if (url) {window.location = url;}
  }

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.