I want to add an array to this working example of my project. You can see the functionality I'm going for if you answer the question in the field and click enter to see it update.
JQuery:
var $input = $("#input");
var questions = ["What's your name?", "Are you married?", "What's your wife's name?", "Do you have children?", "How many children do you have?"];
$(function () {
var scntDiv = $('#namess');
var i = $('#namess p').size() + 1;
$('#addScnt').live('click', function () {
$('<p><label for="names"><input type="text" name="names_' + i + '" id="names_' + i + '"size="30" value="' + $input.val() + '"></label><a href="#" id="remScnt"> Remove</a></p>').appendTo(scntDiv);
i++;
$input.val("Are you married?");
return false;
});
$('#remScnt').live('click', function () {
if (i > 1) {
$(this).parents('p').remove();
i--;
}
return false;
});
});
HTML:
<input type="text" name="input" id="input" size="30" value="What is your name?">
<a href="#" id="addScnt">Enter</a>
<div id="namess">
<div>
<label for="names"></label>
</div>
</div>
http://jsfiddle.net/miketrujillo/nV2tA
I included an array in there just as an example of what I'd like to see in the text field. I've tried adding the questions var into the value for names but it's not working correctly and is breaking the cloning to the box.