i am writing following javascript application to get the data from user. When user select the values from select menu, it show different form elements, based on the option value. I have following code
HTML
<select>
<option value="">hi</option>
<option value="1">1</option>
</select>
<div></div>
Javascript
var myFunc = function () {
var string = '<input><span>+</span>';
$(string).appendTo('div');
$('span').on('click', function () {
myFunc();
})
};
$('select').on('change', function () {
var value = $(this).val();
if (value == 1) {
myFunc();
}
})
My question is when the user click on the plus icon it should show another
input element with the plus mark. when user select the last plus mark same thing should happen.
but the previous plus marks should become a minus. and when the user click on minus all the element below to the that minus mark should be removed.
currently my code generates the input elements. but i dont understand the way of adding a minus marks and removing other elements. and also i need to limit the number of input elemnts to 5. Please help me. :)