Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6139561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:00:21+00:00 2026-05-23T18:00:21+00:00

I am not very experienced just a learner. Now come to the question. I

  • 0

I am not very experienced just a learner.
Now come to the question.
I have a dynamic table codes are below: works fine as intended.

    <head>

    <style type="text/css">
    <!--
    #tblitemsgrid 
    td { 
    padding: 0.5em; 
    }
    .classy0 { background-color: #234567; color: #89abcd; }
    .classy1 { background-color: #89abcd; color: #234567; }

    th { 
    padding: 0.5em;
    background:#39C;
    text-align:center;




    }

    -->
    </style>
    <script type="text/javascript">

    var INPUT_NAME_PREFIX = 'input'; // this is being set via script
    var RADIO_NAME = 'totallyrad'; // this is being set via script
    var TABLE_NAME = 'tblitemsgrid'; // this should be named in the HTML
    var ROW_BASE = 1; // first number (for display)
    var hasLoaded = false;

    window.onload=fillInRows;

    function fillInRows()
    {
    hasLoaded = true;
    addRowToTable();

    }

    // CONFIG:
    // myRowObject is an object for storing information about the table rows
    function myRowObject(one, two, three, four, five)
    {
    this.one = one; // text object
    this.two = two; // text object
    this.three = three; // text object
    this.four = four; // text object


    }

    /*
    * insertRowToTable
    * Insert and reorder
    */
    function insertRowToTable()
    {
    if (hasLoaded) {
    var tbl = document.getElementById(TABLE_NAME);
    var rowToInsertAt = tbl.tBodies[0].rows.length;
    for (var i=0; i<tbl.tBodies[0].rows.length; i++) {
    }
    addRowToTable(rowToInsertAt);
    reorderRows(tbl, rowToInsertAt);

    }
    }

    /*
    * addRowToTable

    function addRowToTable(num)
    {
    if (hasLoaded) {
    var tbl = document.getElementById(TABLE_NAME);
    var nextRow = tbl.tBodies[0].rows.length;
    var iteration = nextRow + ROW_BASE;
    if (num == null) { 
    num = nextRow;
    } else {
    iteration = num + ROW_BASE;
    }

    // add the row
    var row = tbl.tBodies[0].insertRow(num);

    // CONFIG: requires classes named classy0 and classy1
    row.className = 'classy' + (iteration % 2);

    // CONFIG: This whole section can be configured

    // cell 0 - text - Serial Number
    var cell0 = row.insertCell(0);
    var textNode = document.createTextNode(iteration);
    cell0.appendChild(textNode);

    // cell 1 - input text - Account name
    var cell1 = row.insertCell(1);
    var txtInpACC = document.createElement('input');
    txtInpACC.setAttribute('type', 'text');
    txtInpACC.setAttribute('name', 'accname' + iteration);
    txtInpACC.setAttribute('size', '40');
    txtInpACC.setAttribute('value', iteration); 
    cell1.appendChild(txtInpACC);

    // cell 2 - input box- Dr amount
    var cell2 = row.insertCell(2);
    var txtInpDR = document.createElement('input');
    txtInpDR.setAttribute('type', 'text');
    txtInpDR.setAttribute('name', 'DrAmount' + iteration);
    txtInpDR.setAttribute('size', '10');
    txtInpDR.setAttribute('value', iteration); // iteration included for debug purposes
    cell2.appendChild(txtInpDR);


    // cell 3 - input box- Cr amount
    var cell3 = row.insertCell(3);
    var txtInpCR = document.createElement('input');
    txtInpCR.setAttribute('type', 'text');
    txtInpCR.setAttribute('name', 'CrAmount' + iteration);
    txtInpCR.setAttribute('size', '10');
    txtInpCR.setAttribute('value', iteration); // iteration included for debug purposes
    cell3.appendChild(txtInpCR);


    // cell 4 - input button - Delete
    var cell4 = row.insertCell(4);
    var btnEl = document.createElement('input');
    btnEl.setAttribute('type', 'button');
    btnEl.setAttribute('value', 'Delete');
    btnEl.onclick = function () {deleteCurrentRow(this)};
    cell4.appendChild(btnEl);


    // Pass in the elements you want to reference later
    // Store the myRow object in each row
    row.myRow = new myRowObject(textNode, txtInpACC, txtInpDR, txtInpCR, btnEl);
    }
    }

    // CONFIG: this entire function is affected by myRowObject settings

    function deleteCurrentRow(obj)
    {
    if (hasLoaded) {
    var oRows = document.getElementById('tblitemsgrid').getElementsByTagName('tr');
    var iRowCount = (oRows.length - 2);

    if (iRowCount <1+1) {
    alert('Your table has ' + iRowCount + ' row(s). Row count can not be zero.');
    return
    }

    var delRow = obj.parentNode.parentNode;
    var tbl = delRow.parentNode.parentNode;
    var rIndex = delRow.sectionRowIndex;
    var rowArray = new Array(delRow);
    deleteRows(rowArray);
    reorderRows(tbl, rIndex);}

    }

    function reorderRows(tbl, startingIndex)
    {
    if (hasLoaded) {
    if (tbl.tBodies[0].rows[startingIndex]) {
    var count = startingIndex + ROW_BASE;
    for (var i=startingIndex; i<tbl.tBodies[0].rows.length; i++) {

    // CONFIG: next line is affected by myRowObject settings
    tbl.tBodies[0].rows[i].myRow.one.data = count; // text

    // CONFIG: next line is affected by myRowObject settings
    tbl.tBodies[0].rows[i].myRow.two.name = INPUT_NAME_PREFIX + count; // input text

    var tempVal = tbl.tBodies[0].rows[i].myRow.two.value.split(' '); 
    tbl.tBodies[0].rows[i].myRow.two.value = count + ' was' + tempVal[0]; 

    // CONFIG: next line is affected by myRowObject settings
    tbl.tBodies[0].rows[i].myRow.four.value = count; // input radio

    // CONFIG: requires class named classy0 and classy1
    tbl.tBodies[0].rows[i].className = 'classy' + (count % 2);

    count++;
    }
    }
    }
    }

    function deleteRows(rowObjArray)
    {
    if (hasLoaded) {
    for (var i=0; i<rowObjArray.length; i++) {
    var rIndex = rowObjArray[i].sectionRowIndex;
    rowObjArray[i].parentNode.deleteRow(rIndex);
    }
    }
    }

    function openInNewWindow(frm)
    {
    // open a blank window
    var aWindow = window.open('', 'TableAddRow2NewWindow',
    'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');

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

    // submit
    frm.submit();
    }
    </script>
    </head>
    <body>
    <form action="tableaddrow_nw.php" method="get">
    <p>
    <input type="button" value="Add" onclick="addRowToTable();" />
    <input type="button" value="Insert [I]" onclick="insertRowToTable();" />
    <!--<input type="button" value="Delete [D]" onclick="deleteChecked();" />-->
    <input type="button" value="Submit" onclick="openInNewWindow(this.form);" />
    </p>
    <table border="0" cellspacing="0" id="tblitemsgrid" width=600>
    <thead>
    <tr>
    <th colspan="5">Sample table</th>
    </tr>
    <tr>
    <th>E.#</th>
    <th>Account name</th>
    <th>Debit</th>
    <th>Credit</th>
    <th></th>
    </tr>
    </thead>
    <tbody></tbody>
    </table>
    </form>
    </body>
    </html>

This is a processing page:

    <head>
    <title>Table Add Row - new window</title>
    <script language="JavaScript"> 
    <!--
    function printToPage()
    {
    var pos;
    var searchStr = window.location.search;
    var searchArray = searchStr.substring(1,searchStr.length).split('&');
    var htmlOutput = '';
    for (var i=0; i<searchArray.length; i++) {
    htmlOutput += searchArray[i] + '<br />';
    }
    return(htmlOutput);
    }
    //-->
    </script>
    </head>

    <body>
    <b>MREDKJ's Table Add Row</b>
    <br />
    Below should be the name/value pairs that were submitted:
    <p>
    <script language="JavaScript"> 
    <!--
    document.write(printToPage());
    //-->
    </script>
    </p>
    </body>
    </html>

the above displays a result:

accname1=1
DrAmount1=1
CrAmount1=1
input2=2+was2
DrAmount2=2
CrAmount2=2
input3=3+was3
DrAmount3=3
CrAmount3=3
input4=4+was4
DrAmount4=4
CrAmount4=4

how can I pass javascript variables into PHP (which is server side and client side) in the above case ?
thanks alot in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:00:21+00:00Added an answer on May 23, 2026 at 6:00 pm

    You can use jQuery and ajax to pass these informations to server easy way

    And remember. PHP isn’t client side language

    $.ajax({
           'url': 'ajax.php', 
           'type': 'POST',
           'data': 'accname1='+accname1+'&input1='+input1+'&input2='+input2+'&input3='+input3+'&DrAmount1='+DrAmount1+'&DrAmount2='+DrAmount2+'&DrAmount3='+DrAmount3+'&CrAmount1='+CrAmount1'&CrAmount2='+CrAmount2'&CrAmount3='+CrAmount3,
           'success': function(){
                 alert('data sent');
           }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive me if this is a stupid question. I am not very experienced with
Question related to PHP memory-handling from someone not yet very experienced in PHP: If
In a similar vein to my previous question - I'm not a very experienced
I'm not very experienced in JSP. I have an application, which uses the Spring
I am not very experienced with VB.NET but I have to build an application
My question relates to the innards of how Postgres works: I have a table:
I am not very experienced with database and php and I have a problem.
I'm not very experienced with JavaScript, but this code was similar to what I
( Updated a little ) I'm not very experienced with internationalization using PHP, it
I'm a long time developer but not very experienced with DNS. Here's my problem:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.