SitePoint Sponsor

User Tag List

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

    add text fields dynamically using php

    Hi

    i have three fields by name

    Date,Contacts,Rc,
    under this row i have three text fields respectively.I am saving these values in database with an auto value,cid,date,comment and rc.
    can any body help me how to create dynamic text fields under the static fields with an limit of 15 using php not by javascript,because if i have add three dynamic rows of fields,these three rows values should store in database with same cid value
    plz can any one help me?

    shiva

  2. #2
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please post your code so we can see what you are trying to do... I don't understand from your description.
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  3. #3
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure wheeler
    this is my js code

    <script type="text/javascript">
    // Last updated 2006-02-21
    function addRowToTable()
    {
    var tbl = document.getElementById('tblSample');
    var lastRow = tbl.rows.length;
    // if there's no header row in the table, then iteration = lastRow + 1
    var iteration = lastRow;
    var row = tbl.insertRow(lastRow);

    // left cell
    var cellLeft = row.insertCell(0);
    var textNode = document.createTextNode(iteration);
    cellLeft.appendChild(textNode);

    // right cell
    var cellRight = row.insertCell(1);
    var el = document.createElement('input');
    el.type = 'text';
    el.name = 'txtRow' + iteration;
    el.id = 'txtRow' + iteration;
    el.size = 20;

    el.onkeypress = keyPressTest;
    cellRight.appendChild(el);

    // middle cell
    var cellmiddle = row.insertCell(1);
    var e2 = document.createElement('input');
    e2.type = 'text';
    e2.name = 'txtRow' + iteration;
    e2.id = 'txtRow' + iteration;
    e2.size = 20;

    el.onkeypress = keyPressTest;
    cellmiddle.appendChild(e2);

    // Left cell
    var cellleft = row.insertCell(1);
    var e3 = document.createElement('input');
    e3.type = 'text';
    e3.name = 'txtRow' + iteration;
    e3.id = 'txtRow' + iteration;
    e3.size = 20;

    el.onkeypress = keyPressTest;
    cellleft.appendChild(e3);

    }
    function keyPressTest(e, obj)
    {
    var validateChkb = document.getElementById('chkValidateOnKeyPress');
    if (validateChkb.checked) {
    var displayObj = document.getElementById('spanOutput');
    var key;
    if(window.event) {
    key = window.event.keyCode;
    }
    else if(e.which) {
    key = e.which;
    }
    var objId;
    if (obj != null) {
    objId = obj.id;
    } else {
    objId = this.id;
    }
    displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
    }
    }
    function removeRowFromTable()
    {
    var tbl = document.getElementById('tblSample');
    var lastRow = tbl.rows.length;
    if (lastRow > 2) tbl.deleteRow(lastRow - 1);
    }
    function openInNewWindow(frm)
    {
    // open a blank window
    var aWindow = window.open('', 'TableAddRowNewWindow',
    'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');

    // set the target to the blank window
    frm.target = 'TableAddRowNewWindow';

    // submit
    frm.submit();
    }
    function validateRow(frm)
    {
    var chkb = document.getElementById('chkValidate');
    if (chkb.checked) {
    var tbl = document.getElementById('tblSample');
    var lastRow = tbl.rows.length - 1;
    var i;
    for (i=1; i<=lastRow; i++) {
    var aRow = document.getElementById('txtRow' + i);
    if (aRow.value.length <= 0) {
    alert('Row ' + i + ' is empty');
    return;
    }
    }
    }
    openInNewWindow(frm);
    }

    </script>

    and This code exists in the form


    <table border="1" id="tblSample">
    <tr>
    <th colspan="4"><input type="button" value="Add" onclick="addRowToTable();" /><input type="button" value="Remove" onclick="removeRowFromTable();" /></th>
    </tr>
    <tr>
    <td>1</td>
    <td><input type="text" name="dates"
    id="dates" size="20" onkeypress="return submitenter(this,event)" /></td>
    <td><input type="text" name="rc"
    id="rc" size="20" onkeypress="return submitenter(this,event)" /></td>
    <td><input type="text" name="comments"
    id="comments" size="20" onkeypress="return submitenter(this,event)" /></td>

    </tr>
    </table>

    expecting help from 'U' wheeler,
    Thanx ,
    Shiva


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
  •