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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:03:18+00:00 2026-06-07T17:03:18+00:00

I have a PHP while loop that generates a table containing input tags. Each

  • 0

I have a PHP while loop that generates a table containing input tags. Each input box is given a unique name by appending the input box name and the loop value.

<?php
$i=1;
$r=0;
while($i<=$positionjobrows)
{
    ?>
    <tr>
        <td>
            <?PHP echo $i; ?>
        </td>
    <td>
    <input type=text NAME="position<?PHP echo $i; ?>" id="position<?PHP echo $i; ?>"  style="border: 1px solid #2608c3;color:red; width=200px" value="<? echo mysql_result($resultpositionjob,$r,0);?>"> 
    </td>
    <td>
    <input type=text NAME="job<?PHP echo $i; ?>" id="job<?PHP echo $i; ?>"  style="border: 1px solid #2608c3;color:red; width=200px" value="<? echo mysql_result($resultpositionjob,$r,1);?>"> 
    </td>
    <td>
    <SELECT NAME="person<?PHP echo $i; ?>" id="person<?PHP echo $i; ?>" style="border: 1px solid #2608c3;color:red; width=200px" onchange="get(<? echo $i; ?>);"> 
    <OPTION VALUE=0 >
    <?=$optionpeople?> 
    </SELECT>
    </td>
    <td>
    <div id="training<?PHP echo $i; ?>"><font color=grey size=2>Training details will be shown here</div>
    </td>
    </tr>
    <?PHP
    $i++;
    $r++;
    }
    ?>

I am trying to modify my javascript / jquery script to use each of the generated input box names.

For example the input box position will be named position1, position2, position3 etc. I call the script using onchange=”get(row)” where row is the loop instance. so for position1 the onchange will be onchange”get(1)”

This is passed to my javascript / jquery script:

<script type="text/javascript">
        function get(row){

        $.post ('getpeopleinjobs.php',{ 
        postvarposition: form.[position+row].value,
        postvarjob: form.job+row.value, 
        postvarperson: form.person+row.value, 
        postrow: row}, 
            function(output){
                $('#training'+row).html(output).show();
                    });
        alert(postvarposition); 

        }

</script>

As you can see, I want to set the variable postvarposition to the id of the inputbox (position) + the row number. I want to concatenate the two together inside the form.position.value statement. So get(1) will then produce:

postvarposition: form.position1.value

My thinking is along these lines, but is not working:

postvarposition: form.[position+row].value,

How can I concatenate the name of the inputbox against the row?

Thanks as always for the help.

UPDATE

This code below works for the first row where I manually append ‘1’ to the input tag name.

<script type="text/javascript">
        function get(row){
        alert(row);
        $.post ('getpeopleinjobs.php',{ 
        postvarposition: form.position1.value,
        postvarjob: form.job1.value, 
        postvarperson: form.person1.value, 
        postrow: row}, 
            function(output){
                $('#training'+row).html(output).show();
                    });
                }
</script>

I have then tried to change it as advised by machineghost but this still doesnt work. I have confirmed that the value of variable row is 1 with the alert message.

<script type="text/javascript">
        function get(row){
        alert(row);
        $.post ('getpeopleinjobs.php',{ 
        postvarposition: form[position+row].value,
        postvarjob: form[job+row].value, 
        postvarperson: form[person+row].value, 
        postrow: row}, 
            function(output){
                $('#training'+row).html(output).show();
                    });
                }
</script>

Google Chrome (F12) ouputs error Uncaught ReferenceError: position is not defined

any advice or suggestions would be appreciated.

Many 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-06-07T17:03:19+00:00Added an answer on June 7, 2026 at 5:03 pm

    If you want to use the bracket syntax you can’t combine it with period syntax. In other words:

    form.[position+row].value
    

    should be:

    form[position+row].value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script that reads from a pipe in blocking mode. while($input
I have a table that's generated by a normal PHP loop. What I want
I have a file ajax.php that needs to trigger a big while loop and
I have a while loop that populates a dropdown box with values from a
I've got an inventory table that needs to have certain in each row, and
I have a while loop that constructs a url for an SMS api. This
Using PHP , I would like to make a while loop that reads a
I have a dropdown box that I construct with PHP. Here is the code:
I have a while loop that is going through and displaying an RSS icon
I have a large PHP loop that I'm re-using in multiple spots on multiple

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.