Jump to content

Add New Input Text Box with New Name

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Add New Input Text Box with New Name Rate Topic: -----

#1 User is offline   Information 

  • W.R. Private
  • Group: Members
  • Posts: 2
  • Joined: 09-December 08

Posted 09 December 2008 - 07:53 PM

Hi,

I have a form and I'm trying to make it where if a person clicks on add new row or add new text input box that a new one appears on the same page. I'm looking to do this in javascript or php. But I also want to make it so that when a person creates a new input text box that a new name is given to it so that the processform.php page can retrieve the new values.

Here's is the following code that I have in javascript. It adds a new input text box when click, but how can I add it so that a predictive name is automatically given to each new input text box that is to be submitted?

<html>
<head>
<script type="text/javascript">
function insRow()
{
var x=document.getElementById('myTable').insertRow(0);
var y=x.insertCell(0);
y.innerHTML="<input type=text>";
}
</script>
</head>
<body>
<table id="myTable" border="0">
<tr>
<td></td><form action="processform.php" method="post"><input type=text name=A>
</tr>
<br />
</table>
<input type="button" onclick="insRow()" value="Insert row"><br>
<input type="submit" value="submit"/>
</form>
</body>
</html>


Also is there any other ways to do this? Thanks

This post has been edited by Information: 09 December 2008 - 07:56 PM

0

#2 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 10 December 2008 - 12:45 AM

You could do that with php, etc. but i think what you're working on is fine.

First, you have a couple HTML problems. The <form> tag shoud be before the <table> and you closed your <td> before the <input>


Try this out
<script type="text/javascript">
i=1;
function insRow()
{
var x=document.getElementById('myTable').insertRow(0);
var y=x.insertCell(0);
y.innerHTML="<input type=text name=A" + i + ">";
i++;
}
</script>

0

#3 User is offline   Information 

  • W.R. Private
  • Group: Members
  • Posts: 2
  • Joined: 09-December 08

Posted 10 December 2008 - 06:59 AM

Thanks!

I'm not sure what the names for the new input boxes would be when I submit form.

How could one do this in php?
0

#4 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 10 December 2008 - 02:29 PM

They'd be A, A1, A2, A3...

The php code would be longer and wouldn't really be advantageous.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users