Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery - How to get the input value from a label

If I have a bunch of label/selects like:

<label for="blah" class="myClass">
<select id="blah" multiple="multiple" size="5">

How would I get the value of the selected item based off the label?

So far I have..

    $('label[class="myClass"]').each(function(){
        var labelTxt = $(this).text();
        var labelForTxt = $(this).attr('for');
        var inputVal = $('#'+labelForTxt).val();
    });

but inputVal isn't the value I expect to see. Instead I get either null/undefined. Am I missing something?

Thanks!

like image 388
user973479 Avatar asked Sep 12 '25 23:09

user973479


1 Answers

everything is fine, if you hav given close tag for label and select and options in select .check the code , i have modified and implemented. http://jsfiddle.net/XaMg9/5/

like image 142
dku.rajkumar Avatar answered Sep 15 '25 17:09

dku.rajkumar