简体   繁体   中英

How to get value from dynamic textbox with dynamic id

So i have a text box with id :

 <input type="text" name="jview_no[]" id="view'+$sr +'" value="1">

where :

$sr = ($(".my_tr_class").length + 1);

i wanted to put the value of that view+$sr to another textbox, so this is how i do it so far :

<input type="text" name="amount[]" value="'+ $("#view"+$sr).val() + '" > 

but the result is undefined.

the thing is, i don't really know how to do it the right way, would you guys please help me ?

thanks in advance

I don't understand what you exactly want to achieve. If you have only two inputs you can use example below (this is only for your example), but if you have more inputs and you need to match these inputs together, you have read about this in javascript.

 $(document).on('keyup','input[name="jticket_no[]"]', function(){ $(this).parent().next().children()[0].value = $(this).val() })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table style="width: 100%" class="table"> <thead><tr><th>No.</th> <th>Views +5</th> <th>Payment</th> </tr> </thead> <tbody id="table-details"><tr id="row1" class="jdr1"> <td><span class="btn btn-sm btn-default">1</span><input type="hidden" value="6437" name="count[]"></td> <td><input type="text" required="" class="form-control input-sm" placeholder="Views" name="jticket_no[]"></td> <td><input type="text" required="" data-parsley-type="digits" class="form-control input-sm" placeholder="Payment" name="jamount[]"></td> </tr> <tr id="row1" class="jdr1"> <td><span class="btn btn-sm btn-default">2</span><input type="hidden" value="6437" name="count[]"></td> <td><input type="text" required="" class="form-control input-sm" placeholder="Views" name="jticket_no[]"></td> <td><input type="text" required="" data-parsley-type="digits" class="form-control input-sm" placeholder="Payment" name="jamount[]"></td> </tr> </tbody> </table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM