javascript - Add and remove inputs dynamicly with a other input -
i searched lot this, can find +1 -1 solutions. want set number of inputs other input this:
//enter number of inputs (1 start-value) <input type="text" size="3" maxlength="3" id="count" name="count" value="1"> //display number of inputs (1 @ start) <input type="text" size="30" maxlength="30" id="input_1" name="input_1">
when user writes 5 in first field, form should this:
//enter number of inputs (1 start-value) <input type="text" size="3" maxlength="3" id="count" name="count" value="1"> //display number of inputs (1 @ start) <input type="text" size="30" maxlength="30" id="input_1" name="input_1"> <input type="text" size="30" maxlength="30" id="input_2" name="input_2"> <input type="text" size="30" maxlength="30" id="input_3" name="input_3"> <input type="text" size="30" maxlength="30" id="input_4" name="input_4"> <input type="text" size="30" maxlength="30" id="input_5" name="input_5">
how can make this? must use js?
here's simple javascript snippet doesn't make use of frameworks:
function addinputs() { var count = parseint(document.getelementbyid("count").value); (var = 2; <= count; i++) { document.getelementbyid('moreinputs').innerhtml += '<input type="text" name="input_' + + '" id="input_' + + '" />'; } }
in example have add container (div) id 'moreinputs'. however, when calling function more once, not work (e.g. can increase number of input not decrease)
Comments
Post a Comment