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

  • Home
  • SEARCH
  • 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 9214595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:00:17+00:00 2026-06-18T02:00:17+00:00

I am creating a form which fetches the value from the database and stores

  • 0

I am creating a form which fetches the value from the database and stores the value dynamically into a table. I have a button named add which adds a row dynamically when a user press it and I have a hidden counter which counts the rows added.

The problem is, when I fetch the record, the counter shows the number of rows present and when I add a new row it goes back to 1.

If there are two rows in the table, the counter will show 2 but when I try to add a new row the counter shows 1.

Is there any way to set the value from the counter text into the JavaScript variable and increment it?

Here is my JavaScript code:

<script language="javascript" type="text/javascript">
    var jj= 1;
    alert(jj);
    function addRow()
    {
        //alert(jj)
        var tbl = document.getElementById('zimtable');
        var lastRow = tbl.rows.length;
        var iteration = lastRow - 1;
        var row = tbl.insertRow(lastRow);

        var firstCell = row.insertCell(0);
        var el = document.createElement('input');
        el.type = 'text';
        el.name = 'zimname_' + jj;
        el.id = 'zimname_' + jj;
        el.size = 40;
        el.maxlength = 40;
        firstCell.appendChild(el);

        var secondCell = row.insertCell(1);
        var el2 = document.createElement('input');
        el2.type = 'text';
        el2.name = 'zimmob_' + jj;
        el2.id = 'zimmob_' + jj;
        el2.size = 13;
        el2.maxlength = 13;
        secondCell.appendChild(el2);

        // alert(i);
        //$('#hh').val(jj); 
        jj++;
        makhtab.hh.value=jj;

        alert(jj);
    }
</script>

Here is my php code to show the table:

<?php

    $zim = mysql_query("SELECT * FROM `makhzim` WHERE makhcode='$newsid' ORDER BY srno")or die(mysl_error());
    $ctrzim = 0;
    while ($zrow = mysql_fetch_array($zim)){
        $ctrzim++;
        print '<script type="text/javascript">';
        print "alert('$i')";
        print '</script>';
        echo "<tr>";
        echo "<td><input name='zimname_$ctrzim' type='text'  size='40' maxlength='20' value=$zrow[name] /></td>";
        echo "<td><input name='zimmob_$ctrzim'  type='text'   size='13' maxlength='20' value=$zrow[mobile] /></td>";
        echo "</tr>";
    }
    echo "</table>";
    echo "<input type=\"button\" value=\"Add\" onclick=\"addRow();\" /><input id=\"hh\" name=\"hh\" type=\"text\" value= '$ctrzim'/>";
?>
  • 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-06-18T02:00:18+00:00Added an answer on June 18, 2026 at 2:00 am

    In your php code put the value of the counter to a hidden element

    <input type = "hidden"  id = "hiddenElementId" value = "your php counter value"/>
    

    In your javascript

    <script>
         var count;
         window.onload=function(){
             count =   =   document.getElementById("hiddenElementId").value;
         };
         function addRow() {
            alert(count);
            ..
            ..
            count++;
          }
    <script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating one form in html using table. Which have one Drop down
I am working on creating a form which pulls data from a database, and
I am creating a form which adds a table row on a button click
I have a jQuery Model windows which contains a form. On creating of the
I am creating form in access in which i have to implement cascading combo
i am creating a login form in which i have to set a flash
I have this form Im creating and when you click on the Next button
From the tutorial in djangobook.com http://djangobook.com/en/2.0/chapter07/ , I am creating a form which returns
I have a little checkbox on a signup form im creating which 'must' be
I am creating one form which contain table and some buttons. A picture is

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.