Search code examples
javascriptyui

Load a link inside a SELECT tag in YUI


I have a SELECT with many option items like this:

<select>
  <option data-link="http://www.foo.com">Link to Foo website</option>
  <option data-link="http://www.bar.com">Link to Bar website</option>
  ...
</select>

I'd need that when a user change SELECT value, it will be redirected to the corresponding website, which url is in data-link attribute.

My constrain is that I can't use jQuery, I should use YUI.

Please, can you help me?


Solution

  • I've not done much work with YUI, however, when working with it for a similar issue, I came across this post that seemed to work for me. The answer pertained to the code being like follows:

    Y.one("#mySelect").on("change", function() {
       document.location.href = this.get('value'); 
    });