Push values in an array jQuery -



Push values in an array jQuery -

i need array stores selected values given options @ contiguous locations. when run code below, values stored @ same location(0) , rest of array empty.

following html:

<div> <table id="mytable"> <tbody> <tr> <th>robot by</th> <th>robot name</th> <th>status</th> <th>add</th> <th>remove</th> </tr> <tr id="col1"> <td>google</td> <td><em>googlebot</em></td> <td> <select class="myoption"> <option value="same default">same default</option> <option value="allowed">allowed</option> <option value="refused">refused</option> </select></td> <td> <button type="button" class="addc"> add together </button></td> <td> <button type="button" class="removec"> remove </button></td> </tr> <tr id="col2"> <td>msn search</td> <td><em>msnbot</em></td> <td> <select class="myoption"> <option value="same default">same default</option> <option value="allowed">allowed</option> <option value="refused">refused</option> </select></td> <td> <button type="button" class="addc"> add together </button></td> <td> <button type="button" class="removec"> remove </button></td> </tr> <tr id="col3"> <td>yahoo</td> <td><em>yahoo-slurp</em></td> <td> <select class="myoption"> <option value="same default">same default</option> <option value="allowed">allowed</option> <option value="refused">refused</option> </select></td> <td> <button type="button" class="addc"> add together </button></td> <td> <button type="button" class="removec"> remove </button></td> </tr> <tr id="col4"> <td>ask/teoma</td> <td><em>teoma</em></td> <td> <select class="myoption"> <option value="same default">same default</option> <option value="allowed">allowed</option> <option value="refused">refused</option> </select></td> <td> <button type="button" class="addc"> add together </button></td> <td> <button type="button" class="removec"> remove </button></td> </tr> </tbody> </table> </div> <input type="button" value="create robots.txt" id="createfile"> <input type="reset" value="clear all" id="clearall">

following jquery:

$("#createfile").click(function() { $('#mytable tr').find('td').each(function(index) { $(this).find('.myoption').each(function(){ var myarray = []; myarray.push($(".myoption option:selected").text()); });

try (demo):

$("#createfile").click(function() { var values = []; $('#mytable .myoption').each(function(){ values.push($(this).val()); }); console.log(values); });

#mytable .myoption selector enough. .val homecoming selected alternative value.

jquery arrays

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -