Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I create one set of input fields that can store multiple names?

Status
Not open for further replies.

solok

Programmer
Oct 1, 2003
13
US
I have a web page with 6 seperate lines with input fields to input 6 seperate names, license numbers, and remarks. If I have more then 6 names can I create one set (line) of input fields that can accept/store multiple names? If so, how would I save it to a SQL database?
 
I usually use client-side javascript to dynamically add additional rows as the user needs them...

Code:
<table id=myTable>
  <tr id=row1>
    <td><input name="name1"></td>
    <td><input name="remarks1"></td
  </tr>
</table>
<input type=button onClick="addRow()" value="Add Row">
<script>
  rowCt = 1
  function addRow(){
    rowCt ++
    theRow = document.getElementById("row1").cloneNode(true)
    theRow.childNodes[0].firstChild.id = "name" + rowCt
    theRow.childNodes[0].firstChild.value = ""
    theRow.childNodes[1].firstChild.id = "remarks" + rowCt
    theRow.childNodes[1].firstChild.value = ""    

    document.getElementById("myTable").appendChild(theRow)
  }
</script>


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook

 
I appreciate the quick response but have yet to get this code to work. Any suggestions?
 
Sorry, I forgot that tables have a TBODY node that is inferred - here you go...

Code:
<table id=myTable>
  <tr id=row1>
    <td><input name="name1"></td>
    <td><input name="remarks1"></td
  </tr>
</table>
<input type=button onClick="addRow()" value="Add Row">
<script>
  rowCt = 1
  function addRow(){
    rowCt ++
    theRow = document.getElementById("row1").cloneNode(true)
    theRow.childNodes[0].firstChild.id = "name" + rowCt
    theRow.childNodes[0].firstChild.value = ""
    theRow.childNodes[1].firstChild.id = "remarks" + rowCt
    theRow.childNodes[1].firstChild.value = ""    

    document.getElementById("myTable").[blue]firstChild[/blue].appendChild(theRow)
  }
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top