I need to select all values from following input fields to their 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…
The above block is about 49 times… and i want an automated system that splits the text value, and push only “one” character on each next div of attr(new);
how can i do this using jquery. i 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 this doesn’t work…
First things first – don’t use an
IDmore than once. IDs are designed to be unique.Change your
IDsfor classes if they’re not going to be unique.You can implement the solution you need like this:
HTML
jQuery
Working demo on jsfiddle.net.