Jenny Dithe
11-06-2010, 05:12 PM
Hi,
I have a field where you can search members. if you start typing a name it comes up with suggestions, if you click on the suggestion it is populated into that field, then you can keep typing names in the same field to build an array of the members, the suggestion for the second name works fine but if you click on that name it replaces the first name. What I want is for the field to read "John Doe; Jenny Dithe" etc.
Now this is because I am using the reset function, but what I am trying to do is reset the function with existing array + new name and that is not working.
I also tried add text, but say the first person they found is John Doe; and then they search for Jenny Dithe, and type Je before the Suggestion box comes up then what is populated in the text field is "John Doe; Je JennyDithe" - so I went back to reset which should work!! In theory I think.
I also have a hidden field where the individuals listed ID numbers are being listed, to be used for something else. (This is added to through my add text function, my wipe function, gets rid of the suggestion box once it has been cleared.)
So my code is:
<script type="text/javascript">
function loadNames (NID,ThisValue,NewID,ID,DID){
Reset (NID,ThisValue);
addtext(NewID,ID);
Wipe(DID);
}
</script>
<script type="text/javascript">
function Reset(NID,ThisValue){
document.getElementById(NID).value=ThisValue;
}
</script>
<script type="text/javascript">
function addtext(NewID,ID){
var element = document.getElementById(ID).value;
var newtext = NewID;
document.getElementById(ID).value=element+newtext;
}
</script>
<script type="text/javascript">
function Wipe(DID){
document.getElementById(DID).innerHTML=' ';
}
</script>
</head>
<body>
<label class="two"><b>To:</b></label><input type="text" class="input" name="to" id="to" value=""><input type="text" class="input" name="recipient" id="recipient" value="" onkeyup="showHint(this.value, 'getName.php','txtHintTo')" size="70" /><br /><br />
<div id="txtHintTo"></div>
and my getName.php is:
<?php
session_start();
$_SESSION['Id'];
$con = mysql_connect("localhost","user","password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydb", $con);
$q=$HTTP_GET_VARS["q"];
$names = explode("; ",$q);
$to = end($names);
$content = array_pop($names);
$output = count($names);
$result = mysql_query("SELECT * FROM clients INNER JOIN members WHERE ((clients.invitee='{$_SESSION['Id']}' AND clients.invited=members.Id) OR
(clients.invited='{$_SESSION['Id']}' AND clients.invitee=members.Id))
AND client.status='accepted'
AND (members.fullname LIKE '".addslashes($to)."%') ") or die("\nError: (" . mysql_error() . ") " . mysql_error());
if(mysql_num_rows($result) > 0){
while($row= mysql_fetch_array($result)){
if ($output=1){
echo '<input type="button" class="button9" name="companion" id="' . $row['PId'] . '," value="' . $row['fullname'] . '" onclick="loadNames(\'recipient\',\' ' . $row['fullname'] . '; \',\' ' . $row['PId'] . '; \',\'to\',\'txtHintTo\');" />';
} else {
echo '<input type="button" class="button9" name="companion" id="' . $row['PId'] . '," value="' . $row['fullname'] . '" onclick="loadNames(\'recipient\',\'array_pop($q) ' . $row['fullname'] . '; \',\' ' . $row['PId'] . '; \',\'to\',\'txtHintTo\');" />';
}
}
}else {
echo 'no suggestion';
}
?>
Sorry this is so long winded, I hope it is clear.
I have a field where you can search members. if you start typing a name it comes up with suggestions, if you click on the suggestion it is populated into that field, then you can keep typing names in the same field to build an array of the members, the suggestion for the second name works fine but if you click on that name it replaces the first name. What I want is for the field to read "John Doe; Jenny Dithe" etc.
Now this is because I am using the reset function, but what I am trying to do is reset the function with existing array + new name and that is not working.
I also tried add text, but say the first person they found is John Doe; and then they search for Jenny Dithe, and type Je before the Suggestion box comes up then what is populated in the text field is "John Doe; Je JennyDithe" - so I went back to reset which should work!! In theory I think.
I also have a hidden field where the individuals listed ID numbers are being listed, to be used for something else. (This is added to through my add text function, my wipe function, gets rid of the suggestion box once it has been cleared.)
So my code is:
<script type="text/javascript">
function loadNames (NID,ThisValue,NewID,ID,DID){
Reset (NID,ThisValue);
addtext(NewID,ID);
Wipe(DID);
}
</script>
<script type="text/javascript">
function Reset(NID,ThisValue){
document.getElementById(NID).value=ThisValue;
}
</script>
<script type="text/javascript">
function addtext(NewID,ID){
var element = document.getElementById(ID).value;
var newtext = NewID;
document.getElementById(ID).value=element+newtext;
}
</script>
<script type="text/javascript">
function Wipe(DID){
document.getElementById(DID).innerHTML=' ';
}
</script>
</head>
<body>
<label class="two"><b>To:</b></label><input type="text" class="input" name="to" id="to" value=""><input type="text" class="input" name="recipient" id="recipient" value="" onkeyup="showHint(this.value, 'getName.php','txtHintTo')" size="70" /><br /><br />
<div id="txtHintTo"></div>
and my getName.php is:
<?php
session_start();
$_SESSION['Id'];
$con = mysql_connect("localhost","user","password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydb", $con);
$q=$HTTP_GET_VARS["q"];
$names = explode("; ",$q);
$to = end($names);
$content = array_pop($names);
$output = count($names);
$result = mysql_query("SELECT * FROM clients INNER JOIN members WHERE ((clients.invitee='{$_SESSION['Id']}' AND clients.invited=members.Id) OR
(clients.invited='{$_SESSION['Id']}' AND clients.invitee=members.Id))
AND client.status='accepted'
AND (members.fullname LIKE '".addslashes($to)."%') ") or die("\nError: (" . mysql_error() . ") " . mysql_error());
if(mysql_num_rows($result) > 0){
while($row= mysql_fetch_array($result)){
if ($output=1){
echo '<input type="button" class="button9" name="companion" id="' . $row['PId'] . '," value="' . $row['fullname'] . '" onclick="loadNames(\'recipient\',\' ' . $row['fullname'] . '; \',\' ' . $row['PId'] . '; \',\'to\',\'txtHintTo\');" />';
} else {
echo '<input type="button" class="button9" name="companion" id="' . $row['PId'] . '," value="' . $row['fullname'] . '" onclick="loadNames(\'recipient\',\'array_pop($q) ' . $row['fullname'] . '; \',\' ' . $row['PId'] . '; \',\'to\',\'txtHintTo\');" />';
}
}
}else {
echo 'no suggestion';
}
?>
Sorry this is so long winded, I hope it is clear.