micalotl micalotl - 4 months ago 33
PHP Question

Explode textbox comma seperated into individual textbox's

Hi I'm trying to explode this text box into 5 INDIVIDUAL text box's.

Current result

<input name="textfield" type="text" id="textfield" value="2, simon feld, 1968, TAS" size="40">


Desired result

<input name="textfield" type="text" id="textfield" value="2" size="40">
<input name="textfield" type="text" id="textfield" value="simon feld" size="40">
<input name="textfield" type="text" id="textfield" value="1968" size="40">



Answer

Below you can find the working example and FIDDLE

function makeSeperateInputs() {
var arrOfValues = $('#textfield').val().split(',');
for(var i=0, len = arrOfValues.length; i < len; i++) {
$('body').append('<input name="textfield" type="text" id="textfield' + i + '" value="' + arrOfValues[i] + '" size="40"><br>')
}
}
$('body').on('click', '#seperateThem', function() {
makeSeperateInputs()
})
Comments