html - How to get value from input onclick with jQuery -


how can value row click?

here's little example:

<div class="row" id="multirows">     <div>         <div class="col-sm-5"><input id="descrepair_0" name="dynfields[0][descrepair]" class="form-control removediv" type="text"></div>         <div class="col-sm-5"><input id="nestparts_0" name="dynfields[0][nestparts]" class="form-control removediv" type="text"></div>         <div class="col-sm-1 removediv"><input id="edprice_0" name="dynfields[0][edprice]" class="form-control removediv" type="text"></div>         <div class="col-sm-1 removediv"><input id="daterepair_0" name="dynfields[0][daterepair]" class="form-control datebox removediv" type="text"></div>         <input id="repairid_0" name="dynfields[0][repairid]" value="1" class="form-control removediv" type="hidden">         <img class="removerow removeimg removediv" src="img/remove.png" width="100%">     </div>      <div>         <div class="col-sm-5"><input id="descrepair_1" name="dynfields[1][descrepair]" class="form-control removediv" type="text"></div>         <div class="col-sm-5"><input id="nestparts_1" name="dynfields[1][nestparts]" class="form-control removediv" type="text"></div>         <div class="col-sm-1 removediv"><input id="edprice_1" name="dynfields[1][edprice]" class="form-control removediv" type="text"></div>         <div class="col-sm-1 removediv"><input id="daterepair_1" name="dynfields[1][daterepair]" class="form-control datebox removediv" type="text"></div>         <input id="repairid_1" name="dynfields[1][repairid]" value="2" class="form-control removediv" type="hidden">         <img class="removerow removeimg removediv" src="img/remove.png" width="100%"></div>     </div> </div> 

when click on img, want value of hidden input (id="repairid_x). tried several options, not want, happy if help. thanks.

since have 2 child divs in each row each it's input element repairid_ want attach event listener child divs or images:

$('.row > div').on('click', function() {     var val = $('input[id^="repairid_"]', this).val(); }); 

demo

or using image:

$('.row img.removerow').on('click', function() {     var val = $(this).prev().val(); }); 

demo

if want values of 2 hidden inputs irrespective of image clicked use this:

$('img.removerow').on('click', function() {     var values = $(this).closest('.row').find(':hidden[id^="repairid_"]').map(function(i,v) {         return this.value;     }).get().join(','); //result: "1,2" }); 

demo


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -