0

I have here my Javascript code that adds dynamic textbox (row) my problem is how can I save the values from the dynamic textbox to database using PHP script? Hope you can help me guys.. Thanks!

<script type="text/JavaScript"> 
  function addRow(r){ 
  var root = r.parentNode;//the root 
  var allRows = root.getElementsByTagName('tr');//the rows' collection 
  var cRow = allRows[0].cloneNode(true)//the clone of the 1st row 
  var cInp = cRow.getElementsByTagName('input');//the inputs' collection of the 1st row 
  for(var i=0;i<cInp.length;i++){//changes the inputs' names (indexes the names) 
  cInp[i].setAttribute('name',cInp[i].getAttribute('name')+'_'+(allRows.length+1)) 
  } 
  root.appendChild(cRow);
  } 
  function shownames(){ 
  var allInp=document.getElementsByTagName('input'); 
  for(var i=0;i<allInp.length;i++){ 
  alert(allInp[i].name) 
  } 
  } 
  </script> 

My HTML code:

  <form method="POST" action="#"> <table width="1024" border="0" cellspacing="6" cellpadding="0"> <tr>
      <td width="195"><div class="user"><input type="text" name="user_a" id="user"  tabindex="6"/></div></td> 
    <td width="410"><div class="reported"><input type="text" name="user_b" id="reported" tabindex="7"/></div></td> 
    <td width="399"><div class="reported"><input type="text" name="user_c" id="reported" tabindex="8"/></div></td> 
    <td width="10"><input name="button" type="button" value="+" onclick="addRow(this.parentNode.parentNode)"></td> </tr> </table> </form>
7
Contributors
8
Replies
62
Views
4 Years
Discussion Span
Last Post by diafol
2

@miyotz

I have here my Javascript code that adds dynamic textbox (row) my problem is how can I save the values from the dynamic textbox to database using PHP script? Hope you can help me guys.. Thanks!

I don't see any PHP or MYSQL code in your script?

I hope you don't expect someone to write the PHP or MYSQL code for you?

I can tell you no one will write it!

If you don't understand PHP or MYSQL then you should learn it!

Edited by LastMitch: grammer

0

You're adding dynamic textboxes - so I suggest that you use array in name attribute, e.g.

<td width="195"><div class="user"><input type="text" name="user_a[]" id="user"  tabindex="6"/></div></td> 
    <td width="410"><div class="reported"><input type="text" name="user_b[]" id="reported" tabindex="7"/></div></td> 
    <td width="399"><div class="reported"><input type="text" name="user_c[]" id="reported" tabindex="8"/></div></td>

Your ids are wrong and if you need to use them, they will have to be made unique. You can't have identical ids in a page. Also, I wonder about the tabindexes. These will also be duplicated? If so, could be a prob - you tab from user_a to user_a - not user_a to user_b

0

you should probalbly not be cloning the row though you should build a clean row and append it
document.createNewElement("tr")...

using allRows length input.tabIndex=allRows.length

Edited by jstfsklh211

0

I'd wrap the add row into a function:

var rowno = 1; var tabindex = 8;
function addRow(){
    //increment rowno every time this runs - so you can make unique ids if req'd
    //concatenate the tablerow cells while -
    //increment tabindex for each textbox added
    //return the tablerow
}
0

How to remove that generated texboxes?
I have tried all possiblw ways.
Help me out please.
Thaks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.