Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery get dropdown rel value()

how do i get the dropdown rel="30" value?

  <select id="t_dermal_name">
     <option value="1" rel="30">Between Eyebrows</option>
       <option value="7" rel="30">Individual Line Softening</option>
       <option value="2" rel="30">Lip Contouring</option>
   </select>

jquery:

$("#t_dermal_name").change(onSelectChange);

function onSelectChange(){
    var selected = $("#t_dermal_name option:selected");     
    var output = "";
    if(selected.val() != 0){
        output = selected.rel();
    }
    $("#output").html(output);
}
like image 455
tonoslfx Avatar asked Dec 02 '25 08:12

tonoslfx


2 Answers

You can use the :selected selector to find the selected option and retrieve its rel value using the attr() method.

Something like this: http://jsfiddle.net/yAQhq/

$("#t_dermal_name").change(onSelectChange);

function onSelectChange(){
    var output = "",
        $this = $(this);

    if($this.val() != 0){
        output = $this.find('option:selected').attr('rel');
    }
    $("#output").html(output);
}
like image 156
treeface Avatar answered Dec 03 '25 22:12

treeface


$('select[name="X"] option[selected]').attr('data-xxx') was the only thing that worked for me.

like image 23
SexRobot Avatar answered Dec 03 '25 20:12

SexRobot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!