checkbox - jQuery shows "name" instead of "value" -


i have time table checkbox:

<table id="date">     <tr>         <th>sun</th>         <th>mon</th>         <th>tue</th>         <th>wed</th>         <th>thu</th>         <th>fri</th>         <th>sat</th>     </tr>     <tr>         <td><input type="checkbox" name="sun" id="sun" value="0" /></td>         <td><input type="checkbox" name="mon" id="mon" value="1" /></td>         <td><input type="checkbox" name="tue" id="tue" value="2" /></td>         <td><input type="checkbox" name="wed" id="wed" value="3" /></td>         <td><input type="checkbox" name="thu" id="thu" value="4" /></td>         <td><input type="checkbox" name="fri" id="fir" value="5" /></td>         <td><input type="checkbox" name="sat" id="sat" value="6" /></td>     </tr> </table> <p><span id="datevalue"></span></p> <button id="datesave">add</button> 

and jquery part:

$(function() {     function datevalue() {         var values = [];         $('#date :checked').each(function () {             values.push($(this).val());         });          $('#datevalue').text(values);     }      $(function () {         $('#datesave').click(datevalue);             $('#datevalue').text(values);     });      $(function () {         $('#datedate input').click(datevalue);             datevalue();     });  }); 

when select checkbox , click button, checkbox's "value" dynamically input <span>, want show checkbox's "name" instead of "value", if select checkbox, <span> show "mon,tue,wed,thu"...etc, not "1,2,3,4"... how fix code?

so use:

values.push(this.name); // or $(this).attr('name') 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -