jquery - how to get selected text from html select which dynamically is created? -
this part of 1 page numberofp integer database , variable.
<div> <% string matn = ""; (int = 0; < numberofp; i++) { matn+= " <div class='cmsdiv'>"; matn += "<input id='text"+i+"' class='labelhid' type='text' />"; matn += "<select id='select"+i+"' class='drophid'>"; matn += "<option>value= '"+ "خیلی زیاد"+"'>خیلی زیاد" + " <option value= '"+"زیاد'"+">زیاد"; matn += "</select>"; matn += "</div>"; response.write(matn); matn = ""; } %> </div>
now want know in each "cmsdiv" text of html select, , value , change 3rd item of class (which has 3 element) in code behind.
i wrote code selected item , pour label , got label. not work. why?
<script type="text/javascript"> $(document).ready(function () { $('.cmsdiv .drophid').each(function() { var selectedtext = $(this).find('option:selected').text(); document.getelementbyid("labelhid").value = selectedtext; }); }); </script>
your select tag has id attribute. make while loop , increment inside of it, break when no longer find object:
var = 0; while (true) { var select = document.getelementbyid('select' + i); if (!select) {break;} i++; }
Comments
Post a Comment