SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dynamic text fields using javascript

    hi all,

    i have created dynamic text fields using javascript,as far as i know its working properly,but i unable to store the dynamic text field values to the database ,first of all i am facing the problem to pass the values from the form...

    plz any body can help me....
    here is the script

    <script language="javascript">
    //add a new row to the table
    function addRow()
    {
    //add a row to the rows collection and get a reference to the newly added row
    var newRow = document.all("tblGrid").insertRow();
    //add 3 cells (<td>) to the new row and set the innerHTML to contain text boxes
    var oCell = newRow.insertCell();
    oCell.innerHTML = "<input type='text' name='latestdate1' onKeyPress='return submitenter(this,event)'>";

    oCell = newRow.insertCell();
    oCell.innerHTML = "<input type='text' name='comments' onKeyPress='return submitenter(this,event)'>";

    oCell = newRow.insertCell();
    oCell.innerHTML = "<input type='text' name='rc1' onKeyPress='return submitenter(this,event)'> &nbsp;&nbsp;<input type='button' value='Delete' onclick='removeRow(this);'/>";
    }

    //deletes the specified row from the table
    function removeRow(src)
    {
    /* src refers to the input button that was clicked.
    to get a reference to the containing <tr> element,
    get the parent of the parent (in this case case <tr>)
    */
    var oRow = src.parentElement.parentElement;

    //once the row reference is obtained, delete it passing in its rowIndex
    document.all("tblGrid").deleteRow(oRow.rowIndex);
    }

    </script>

    and this is in the form

    <table id="tblGrid" style="table-layout:fixed">
    <tr>
    <td width="150px" class="tblhead">Date</td>
    <td width="150px" class="tblhead">Comments</td>
    <td width="250px" class="tblhead">Rc

    <input type="button" value="Add" onClick="addRow();"/></td>
    </tr>
    <tr>
    <td><input type="text" name="date" onkeypress="return submitenter(this,event)" value="<?=$contactdate?>" /></td>
    <td><input type="text" name="comment1" onkeypress="return submitenter(this,event)" value="<?=$comments1?>"/></td>
    <td><input type="text" name="rc2" onkeypress="return submitenter(this,event)" value="<?=$rc?>"/> &nbsp;&nbsp;<input type="button" value="Delete" onClick="removeRow(this);" /></td>
    </tr>
    </table>

  2. #2
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are not changing the name of the field that u are adding dynamically
    make sure that u add the variable like name="latestdate" + i
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •