master_programmer
asked on
ADD TEXT ,EVERY TIME THE BUTTON HITS
hi,
I want to create button on jsp form, every time the user clicks the button an input of type text is added to the form, HOW I CAN DO THIS
IS IT A FUNCTION, because the onclick didn't call this function
I want to create button on jsp form, every time the user clicks the button an input of type text is added to the form, HOW I CAN DO THIS
IS IT A FUNCTION, because the onclick didn't call this function
<head>
<script>
var arrInput = new Array(0);
var arrInputValue = new Array(0);
function addInput() {
arrInput.push(arrInput.length);
arrInputValue.push("");
display();
}
function display() {
document.getElementById('parah').innerHTML="";
for (intI=0;intI<arrInput.length;intI++) {
document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
}
}
function saveValue(intId,strValue) {
arrInputValue[intId]=strValue;
}
function createInput(id,value) {
return "<input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+
value +"'><br>";
}
function deleteInput() {
if (arrInput.length > 0) {
arrInput.pop();
arrInputValue.pop();
}
display();
}
</script>
</head>
<body>
<form>
<input type="button" value="add item" onclick="addInput();" />
</form>
</body>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Change
>>document.getElementById( 'parah').i nnerHTML=" ";
to
var elem = document.getElementById('p arah');
alert(elem);
elem.innerHTML = "";
and tell us what you see
>>document.getElementById(
to
var elem = document.getElementById('p
alert(elem);
elem.innerHTML = "";
and tell us what you see
ASKER
it did not work , it generate error from statment( document.getElementById('p
where exactly should I add this statment?
and where I have to put <div id="parah"></div>
show me this on my code?