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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:04:14+00:00 2026-05-27T05:04:14+00:00

This is what I want to know. I have a table which has the

  • 0

This is what I want to know. I have a table which has the number of rows depended on what the number is in the spinner. This does work e.g. If I enter 25 in spinner it comes up with 25 rows, if I enter 7 in spinner comes with 7 rows.

So my problem is this:

Let’s say there are a number of rows in a table. What I have is a textarea where the user enters in their question and then submits the question, the question should be inserted and appear in the first row of the table under the “Question” column, the textarea goes blank and the user enters in his second question, if the user submits this then the question would appear in the second row, 3rd question into 3rd row, 4th question 4th into row etc.

Problem is that I do not know how to do this. Can somebody please be able to show me how to achieve this. I am not a strong Javascript programmer, I am more a of an Oracle and MYSQL programmer but I need to use Javascript for my project.

Any help will be greatly appreciated

Below is my Javascript code:

              <script type="text/javascript">

function insertQuestion() {   

            var qandatable =  document.getElementById("qandatbl"); 
            var questionDiv = document.getElementById("question");
            var getQuestion = document.getElementById("questionTextarea");     

            var rowCount = qandatable.rows.length;
        var row = qandatable.insertRow(rowCount);

        var questionCell = row.insertCell(getQuestion);

            questionCell.innerHTML = getQuestion.value; 
            }

              </script>

Below is html code:

//table where questions would be stored

    <table id="qandatbl" align="center">
    <thead>
    <tr>
    <th><span id="qidhead">Question No</span></th>
    <th><span id="questionhead">Question</span></th>
    </tr>
    </thead>
    <tbody>
    <?php
    $spinnerCount = $_POST['textQuestion'];
if($spinnerCount > 0) {
   for($i = 1; $i <= $spinnerCount; $i++) {?>

    <tr>
    <td id="qid"><?php echo $i; ?></td>
    <td id="question"></td>
    </tr>
    </tbody>
    <?php
}
}
?>
</table>

//table which consists of textarea and submit button

<form id="enter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<table id='middleDetails' border='1'>
<tr>
<th class='tblheading' colspan='2'>SESSION DETAILS</th>
</tr>
<tr>
<td id="questionNum">Question No </td>
</tr>
<tr>
<td id="questionContent">Question:</td> 
<td id="questionTextarea"><textarea rows="5" cols="40" id="questionTxt" name="questionText"></textarea></td>
</tr>
<tr>
<td id="addQuestionRow" colspan='2'><input id="addQuestion" type="button" value="Add Question" name="addQuestionBtn" onClick="insertQuestion()" /></td>
</tr>
</table>
</form>
  • 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-27T05:04:14+00:00Added an answer on May 27, 2026 at 5:04 am

    You first will have to create row and cell elements, before you can add them to the table.

    var table = document.getElementById("qandatbl");
    var tableBody = table.tBodies[0];
    var textarea = document.getElementById("questionTxt");
    
    var row = document.createElement("tr");
    tableBody.appendChild(row);
    
    var enumeratorCell = document.createElement("td");
    enumeratorCell.className = "qid";
    row.appendChild(enumeratorCell);
    var questionCell = document.createElement("td");
    questionCell.className = "question";
    row.appendChild(questionCell);
    
    var rowCount = tableBody.rows.length;
    var enumeratorContent = document.createTextNode(rowCount);
    enumeratorCell.appendChild(enumeratorContent);
    var questionText = textarea.value;
    var questionContent = document.createTextNode(questionText);
    questionCell.appendChild(questionContent);
    

    Your html should look like this:

    <table id="qandatbl" align="center">
        <thead>
            <tr>
                <th id="qidhead">Question No</th>
                <th id="questionhead">Question</th>
            </tr>
        </thead>
        <tbody>
    <?php
        $spinnerCount = $_POST['textQuestion'];
        if ($spinnerCount > 0) {
           for($i = 1; $i <= $spinnerCount; $i++) {
    ?>
             <tr>
                <td class="qid"><?php echo $i; ?></td>
                <td class="question"></td>
             </tr>
    <?php
            }
        }
    ?>
        </tbody>
    </table>
    <!-- table which consists of textarea and submit button -->
    <form id="enter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
        <table id='middleDetails' border='1'>
            <tr>
                <th class='tblheading' colspan='2'>SESSION DETAILS</th>
            </tr>
            <tr>
                <td id="questionNum">Question No </td>
            </tr>
            <tr>
                <td id="questionContent">Question:</td> 
                <td id="questionTextareaCell"><textarea id="questionTxt" rows="5" cols="40" name="questionText"></textarea></td>
            </tr>
            <tr>
                <td id="addQuestionRow" colspan='2'><input id="addQuestion" type="button" value="Add Question" name="addQuestionBtn" onClick="insertQuestion()" /></td>
            </tr>
        </table>
    </form>
    

    You should not use ids for cells your generating more than once, because an id should be unique per document.

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

Sidebar

Related Questions

I have a table which has 5 rows. When a user clicks on a
I have a table which has rows that alternate colors, when I hover over
I want to know what this looks like. I don't have any ideas about
I want to do this in C#, but I don't know how: I have
I want to get this straight. I know what DLL's are. I have done
I want to know what does RETURN_VALUE mean! I'm stuck at this thing. How
i have a table campaign which has details of campaign mails sent. campaign_table: campaign_id
I have a table in MySql DB which I want to load it to
I have a table that has two columns, ID and Value. For this example
I have a table y Which has two columns a and b Entries are:

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.