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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:56:51+00:00 2026-05-25T06:56:51+00:00

I am completely new to web development and this is my first question on

  • 0

I am completely new to web development and this is my first question on the site.

I am experimenting with the jQuery autocomplete widget with Joomla (hence the jQuery calls), and have mangaged to get it working via a database connection for the first text row input in my table, txtRow1. This input successfully fires the autocomplete widget for stock names.

When I use the ‘add’ row button, the autocomplete no longer works for the next row, txtRow2. How can I make the autocomplete function fire for all the txtRow input rows on the table?

I tried to use the id ‘starts with’ expression, as all the table inputs will be called txtRowX, but it still only works for the first one, txtRow1.

As you can probably tell, all the code is taken from web tutorials and is the work of others.

Thankyou for your time.

UPDATE: Thanks to Griegs linking to another question, the following code is working, but I don’t know why:

   jQuery(function(){
   jQuery('[id^="txtRow"]').live('keyup.autocomplete', function(){
   jQuery(this).autocomplete({
    source : "stockdata.php",
    minLength: 2
    });
    });
    });

The HTML:

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

    jQuery('[id^="txtRow"]').autocomplete({
            source: "stockdata.php",
            minLength: 2
        });
    });

function addRowToTable()
{
var tbl = document.getElementById('tblSample');
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);

// left cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
cellLeft.appendChild(textNode);

// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.type = 'text';
el.name = 'txtRow' + iteration;
el.id = 'txtRow' + iteration;
el.size = 40;

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

// select cell
var cellRightSel = row.insertCell(2);
var sel = document.createElement('select');
sel.name = 'selRow' + iteration;
sel.options[0] = new Option('text zero', 'value0');
sel.options[1] = new Option('text one', 'value1');
cellRightSel.appendChild(sel);

}
</script>

<form action="tableaddrow_nw.html" method="get">
<p>
<input type="button" value="Add" onclick="addRowToTable();" />
<input type="button" value="Remove" onclick="removeRowFromTable();" />
<input type="button" value="Submit" onclick="validateRow(this.form);" />
<input type="checkbox" id="chkValidate" /> Validate Submit
</p>
<table border="1" id="tblSample">
<tr>
<th colspan="3">Stocks</th>
</tr>
<tr>
<td>1</td>
<td><input type="text" name="txtRow1" id="txtRow1" size="40" /></td>
<td>
<select name="selRow0">
<option value="value0">text zero</option>
<option value="value1">text one</option>
</select>
</td>
</tr>
</table>
</form>

The php file:

<?php
$dbhost = 'host';
$dbuser = 'user';
$dbpass = 'pass';
$dbname = 'database';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

$return_arr = array();

/* If connection to database, run sql statement. */
if ($conn)
{
$fetch = mysql_query("SELECT * FROM stocknameticker where stock_name like '%" . mysql_real_escape_string($_GET['term']) . "%'"); 

/* Retrieve and store in array the results of the query.*/
while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
    $row_array['id'] = $row['s_id'];
    $row_array['value'] = $row['stock_name'];
    $row_array['abbrev'] = $row['stock_ticker'];

    array_push($return_arr,$row_array);
}
}

mysql_close($conn);

echo json_encode($return_arr);

?>
  • 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-25T06:56:51+00:00Added an answer on May 25, 2026 at 6:56 am

    When dealing with dynamicaly created elements you need to use the live jquery keyword.

    $('[id^="txtRow"]').live("autocomplete", function(){
    //your code here
    });
    

    edit

    This might help too; Bind jQuery UI autocomplete using .live()

    When you dynamically create an element on a web page, jQuery will not automatially bind it to any events.

    So when you have;

    $(".MyElement").click(...
    

    the click event will only apply to elements that were present when the page was loaded.

    If you now add a new element and want the click even to be applied to it you need to do;

    $(".MyElement").live("click", function(...
    

    That instructs jQuery to scan the document and attach events to newly created elements.

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

Sidebar

Related Questions

I'm completely new to the iPhone, so this is a newbie question. The web
Firstly, I should say I'm completely new to Pylons, trying to learn web development
We're starting new web site development with Umbraco, and having some difficulties with optimal
I'm completely new to the Spring framework (and most web development in general), but
I am completely new to iOS development (I'm a .NET dev). I am experimenting
I'm completely new in web service. I want to study about it and the
Completely new to asp.net mvc... completely new to web apps so bear with me...
I am new in android development. Please check this url - http://mobileecommerce.site247365.com/admin/catdata.xml Please check
I'm completely new to Android development, but I just got a HTC Hero and
After the release of the new web site I've developed I have a strange

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.