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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:58:36+00:00 2026-06-14T08:58:36+00:00

I have a web form that contains a javascript / php autocomplete for an

  • 0

I have a web form that contains a javascript / php autocomplete for an input field.

problem is that this input field sits inside a PHP loop which repeats 50 times. I use the loop to give each input a unique name and id.

The javascript is hardcoded to populate input field “inputString” and display possible suggestions in div “suggestions”

with the loop, I give each input box a unique name “inputstring1”, “inputstring2”, “inputstring3” etc etc.

I need to be able to populate the inputstring that is currently being worked on.

how can I pass the variable “inputstringX” to the javascript so it populates the correct input box?
same applies to the div “suggestion” so that it displays nex tto the correct input box?

javascript is:

<script type="text/javascript">
    function lookup(inputString) {
        if(inputString.length == 0) {
            // Hide the suggestion box.
            $('#suggestions').hide();
        } else {
            $.post("autocompleteperson.php", {queryString: ""+inputString+""}, function(data){
                if(data.length >0) {
                    $('#suggestions').show();
                    $('#autoSuggestionsList').html(data);
                }
            });
        }
    } // lookup

    function fill(thisValue) {
        $('#inputString').val(thisValue);
        setTimeout("$('#suggestions').hide();", 200);
    }
</script>

and php/html is:

<table>
                <?
                    for ( $i = 1; $i <=50; $i++ ) { 
                        ?>
                            <tr>
                                <td> Job <? echo  $i; ?></td>
                                <td>
                                    <SELECT NAME=job<? echo $i; ?> id=job<? echo $i; ?> style="width:150px;border: 1px solid #2608c3;color:red"> 
                                    <OPTION VALUE=0 ></option>
                                    <option>
                                    <?=$optionjobs?> 
                                    </option>
                                    </SELECT>
                                </td>
                                <td> Person </td>
                                <td>
                                    <div>
                                        <input type="text" size="30" value="" id="inputString<? echo  $i; ?>" onkeyup="lookup(this.value);" onblur="fill();" />
                                    </div>
                                    <div class="suggestionsBox" id="suggestions<? echo  $i; ?>" style="display: none;">
                                        <img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
                                        <div class="suggestionList" id="autoSuggestionsList">
                                            &nbsp;
                                        </div>
                                    </div>  
                                </td>
                            </tr>
                        <?
                            }
                        ?>
                </table>

Thanks for yourideas and for your time,

  • 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-14T08:58:37+00:00Added an answer on June 14, 2026 at 8:58 am

    Don’t use the onkeyup html attribute and use the jQuery functions to attach your function. So you can use this to retrieve your input.

    $(function() {
        var inputs = $('input[type="text"]'); // You may want to use a css class instead of that
        inputs.keyup(function() {
             // Here, this == the input. So you can't get the id by using $(this).attr('id').
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web site that contains an HTML form, in this form I
I have a web form that contains lots of JavaScript functionalities to manipulate the
I currently have a web form aspx page that calls RegisterClientScriptBlock. This sends down
I'm trying to create a web form that contains checkboxes, among other input elements,
I have a web form that contains several inputs, some of which are positioned
I have a web form that contains a usercontrol and I would like to
I have a ASP.Net web form that contains both text box fields and hidden
I have a web form that inserts a row into an SQL Server 2008
I have a web form that collects information and submits it to a cgi
I have a web form that manipulates records in a MySQL database. I have

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.