Solved

ADD TEXT ,EVERY TIME THE BUTTON HITS

Posted on 2007-12-03
3
154 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I   ajax html table  rows? 20 63
ForLoop Example 3 40
How to avoid jquery conflicts in Wordpress ? 4 24
Way to decrease size of apk file 9 45
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now