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 4019888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:09:37+00:00 2026-05-20T10:09:37+00:00

Bear with me—this might be a bit confusing! I have a javascript that adds

  • 0

Bear with me—this might be a bit confusing!

I have a javascript that adds (or removes) a new textarea + hidden field (to denote incrementation) to a form when a button is pushed. Here’s the code:

function addRowToTable()
{ 

  var tbl = document.getElementById('convention');
  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);



  // right cell
  var cellRight = row.insertCell(0);

  var el = document.createElement('textarea');
  el.rows = '2';
  el.cols = '80';
  el.name = 'conventionSkill' + iteration;
  el.size = 40;

    var el2 = document.createElement('input');
      el2.value = iteration;
  el2.type = 'hidden';
  el2.name = 'conventioni';



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


}

function removeRowFromTable()
{
  var tbl = document.getElementById('convention');
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}

This is appended to a form which is being presented through the following code:

//Convention




 echo "<form action='index.php?viewrubric=".$_GET['viewrubric']."&class=".$_GET['class']."' method='POST'>";
echo "<input type='hidden' name='rubricid' value='".$id."' />";
$sql2 = "select * from rubrics_convention where rubricid = '$id'";
$result2 = mysql_query($sql2) or die (mysql_error());

?>
<h3>Habit of Convention</h3>
<table>
<tr><td>
<label>Habit Description: </td></tr></label></table><textarea name='conventionDescription' rows='2' cols='80'><? echo $description; ?></textarea><br />

<table id="convention">
<tr><td><label>Skill Descriptions: </label>
</td></tr>

<?
while($row2=mysql_fetch_array($result2)) {
$convention_i++;
echo "<tr><td><textarea ".$readonly." name='convention_".$row2['id']."' rows='2' cols='80'>".$row2['skill']."</textarea></td></tr>";
}
echo "<input type='hidden' value=".$convention_i." name='conventioni' />";


echo "</table>";
echo '<input type="button" value="Add" onClick="addRowToTable();" />
<input type="button" value="Remove" onClick="removeRowFromTable();" />
';

Essentially, this is checking the database (rubrics_convention) for what has already been submitted. It populates the textareas with what’s there. Now, I want it to be possible for a user to click the Add button and add a new textarea. The script right now does this, but when I submit, it doesn’t even recognize convention_i’s new value, or the new skill.

Processing the form:

if(isset($_POST['update'])) {
//Convention

echo $_POST['conventioni'];
}

Outputting 3, not 4, even after adding new form elements through javascript.

When I did “view selection source” in Firefox after clicking the “Add” button, here’s the output:

  <input value="3" name="conventioni" type="hidden" />

  <table id="convention">
    <tbody>
      <tr>
        <td><label>Skill Descriptions:</label></td>
      </tr>

      <tr>
        <td>
        <textarea name="convention_1" rows="2" cols="80">
habit 1
</textarea></td>
      </tr>

      <tr>
        <td>
        <textarea name="convention_2" rows="2" cols="80">
habit 2
</textarea></td>
      </tr>

      <tr>
        <td>
        <textarea name="convention_3" rows="2" cols="80">
testest
</textarea></td>
      </tr>

      <tr>
        <td>
        <textarea name="conventionSkill4" cols="80" rows="2">
</textarea><input name="conventioni" value="4" type="hidden" /></td>
      </tr>
    </tbody>
  </table>


    <input value="Add" onclick="addRowToTable();" type="button" /> <input value="Remove"
    onclick="removeRowFromTable();" type="button" />

Based on this output, you can clearly see that it’s seeing the new conventioni value (the initial was 3, the javascript inserted a new one with a value of 4). However, when submitting the form, it completely ignores that new value and looks at the 3 instead. It doesn’t even recognize conventionSkill4 as being there.

Any ideas? Thanks!

  • 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-20T10:09:38+00:00Added an answer on May 20, 2026 at 10:09 am

    It looks to me as if you’re creating a new “conventioni” <input> each time you add a row, rather than simply updating the value of the input that’s already there. The result will be that your server will get multiple parameters called “conventioni”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.