javascript - How can I bind a link(href) to any of the dropdown options? -


i have dropdown-menu auto populate base on ajax call.

before ajax

enter image description here

after ajax

enter image description here


they in dom

html

<select class="rn-dropdown" id="rn-dd" href="http://localhost:8080/bim/teacher/reports/section-exercise/assignment?assessmentid=206a9246-ce83-412b-b8ad-6b3e28be44e3&amp;classroomid=722bfadb-9774-4d59-9a47-89ac9a7a8f9a">     <option value="class-view">class view</option>     <option value="s-00586">student s00586</option>     <option value="s-00587">student s00587</option>     <option value="s-00588">student s00588</option>     <option value="s-00589">student s00589</option>     <option value="s-00590">student s00590</option> </select>  _ 

my goal re-direct each student href(www.site.com). i'm not how done.

this i've

jquery

// auto populate dropdown-menu $("#rn-dd.rn-dropdown").append('<option value="' + userid + '"> <a href="">' + name + '</a></option>');  // dropdown-menu change $('#rn-dd').on('change', function() {     $(this).find("a").attr('href', "www.google.com"); }); 

any helps / hints mean lot me.

use custom data-* attribute set base href change event - use location.href change:

<select class="rn-dropdown" id="rn-dd" data-href="http://localhost:8080/bim/teacher/reports/section-exercise/assignment?assessmentid=206a9246-ce83-412b-b8ad-6b3e28be44e3&amp;classroomid=722bfadb-9774-4d59-9a47-89ac9a7a8f9a"> 

and js:

$('#rn-dd').on('change', function() {     var selectedvalue = this.value;     var basehref = $(this).data("href");      //do logic on href want     //not sure based on question     var href = basehref; //magic      //redirect     location.href = href; }); 

Comments