arrays - how to push text values to their parent and siblings div. using jquery -


i need select values following input fields respective divs.. see bellow

<div id='table_row_div'>   <div id='txtbox'><input type=text name='from' value='<?php echo $someval?>'></div>   <div id='splited'>     <div new="0"><div>i want text's splited value here</div>     <div new="1"><div>i want text's splited value here</div>     <div new="2"><div>i want text's splited value here</div>   </div> </div> 

these input text fileds contains (1,0,0), (0,1,1), (1,0,1) type values... above block 49 times... , want automated system splits text value, , push "one" character on each next div of attr(new);

how can using jquery. tried following type of code..

var inputval = $("#table_row_div #txtbox input"); var arrayfromdb = inputval.val().split(',');   inputval.closest('div').closest('div').find('div[new~="0"]').text(arrayfromdb[0]); inputval.closest('div').closest('div').find('div[new~="1"]').text(arrayfromdb[1]); inputval.closest('div').closest('div').find('div[new~="2"]').text(arrayfromdb[2]); 

but doesn't work...

first things first - don't use id more once. ids designed unique.

change ids classes if they're not going unique.

you can implement solution need this:

html

<div class='table_row_div'>     <div>         <input type='text' class='txtbox' name='from' value='<?php echo $someval?>'>     </div>     <div class='split'>         <div new="0">first split value</div>         <div new="1">second split value</div>         <div new="2">third split value</div>     </div> </div> 

jquery

$('.txtbox').each(function() {     var arrayfromdb = $(this).val().split(',');     var splitdiv = $(this).closest('.table_row_div').find('.split');     $('div[new~="0"]', splitdiv).text(arrayfromdb[0]);     $('div[new~="1"]', splitdiv).text(arrayfromdb[1]);     $('div[new~="2"]', splitdiv).text(arrayfromdb[2]); }); 

working demo on jsfiddle.net.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -