Solved

ADD TEXT ,EVERY TIME THE BUTTON HITS

Posted on 2007-12-03
3
155 Views
Last Modified: 2010-04-01
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

0
Comment
Question by:master_programmer
3 Comments
 
LVL 17

Accepted Solution

by:
gops1 earned 500 total points
ID: 20394736
You are missing this object inside your body

document.getElementById('parah')

where is parah?

Create this object:-> <div id="parah"></div>
0
 

Author Comment

by:master_programmer
ID: 20394782
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?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20394792
Change

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

to

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

and tell us what you see
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question