Link to home
Start Free TrialLog in
Avatar of master_programmer
master_programmerFlag for Saudi Arabia

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
<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>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gops1
gops1
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of master_programmer

ASKER

hi,
it did not work , it generate error from statment( document.getElementById('parah'))
where exactly should I add this statment?
and where I have to put <div id="parah"></div>
show me this on my code?
Avatar of CEHJ
Change

>>document.getElementById('parah').innerHTML="";

to

var elem = document.getElementById('parah');
alert(elem);
elem.innerHTML = "";

and tell us what you see