Reputation: 305
echo "<table width='234' border='1'>";
while(strtotime($USA_START) <= strtotime($USA_END))
{
$day_num = date('d', strtotime($USA_START));
$day_name = date('l', strtotime($USA_START));
echo "<tr><td>$day_num </td><td> $USA_START</td> <td> $day_name</td><td><input type='text' name='txtRep[]' ></td></tr>";
$USA_START = date("Y-m-d", strtotime("+1 day", strtotime($USA_START)));
}
echo "</table>";
I have above php code which has a loop and create a textbox for each record in a line.
When it is outside the php codes (that means when it is in pure html codes) I have successfully auto completed the below textbox.
<td><input type='text' name='txtRep[]' ></td>
with JQuery. But when I created this inside PHP tags by echoing the textbox, the auto complete process does not work?
Can anybody suggest an approach or is this impossible?
Here is the PHP code for auto complete
<?php
require_once "../DCR/connection/conn.php";
$q = strtolower($_GET["q"]);
if (!$q) return;
$query = "select * from REPPROF where REPTYPE='Mrep' and (REPNAME like '%".strtoupper($q)."%' or REPCODE like '%".strtoupper($q)."%')";
$statement = oci_parse ($connection, $query);
oci_execute ($statement);
while ($row = oci_fetch_array ($statement, OCI_BOTH)){
$txt1=$row['REPCODE'];
$txt2=$row['REPNAME'];
$B=$txt1.'~'.$txt2;
echo "$B\n";
//echo $query;
}
oci_close($connection);
?>
and Jquery
$().ready(function() {
$("#txtMedRep").autocomplete("Mrep_auto_complete.php", { width: 200,max: 20,selectFirst: false});
});
Upvotes: 2
Views: 240
Reputation: 62088
Since you've edited the question, there's now no longer element with ID "txtMedRep". So the Javascript will not add the autocomplete to anything.
Define your textbox with a class, something like:
<input type='text' name='txtRep[]' class='autocomplete'>
Then change your autocomplete definition to:
$().ready(function() {
$(".autocomplete").autocomplete("Mrep_auto_complete.php", { width: 200,max: 20,selectFirst: false});
});
This will cause it to add the autocomplete functionality to all elements which have the "autocomplete" class.
Upvotes: 1
Reputation: 1667
The problem is not in PHP (anymore). It will output names for the inputs just fine. But JQuery tries to attach to an unknown HTML element id. $("#txtMedRep")
does not exist anymore (after some edits you made).
To fix it, try:
$().ready(function() {
$("input").autocomplete("Mrep_auto_complete.php", { width: 200,max: 20,selectFirst: false});
});
Which is off course ALL inputs, but outputting a class on these inputs that is easily fixed
Upvotes: 1