[solved] Javascript this/object orientated problems
Posted: Tue Jan 20, 2009 6:29 am
Hi
I have been creating a webpage that has a searchbox with a real-time AJAX autosuggest feature, however have come up against a slight problem...
I've managed to get the search function to use a MySQL database to find names similar to the text entered so far... and return the results as a list like this...
The fillName() function looks like this...
The details of all the returned search results display into a <div>, and when a name is selected it (should) display it in the searchfield (LastName). However, when I try selecting a name, all I get at the moment is 'undefined', so I must be going wrong somewhere in my Javascript object selection; I've tried various ways of using the 'this' keyword, but can't seem to find the right way of getting the value of the name in the list to then display in the field...
Can anybody give me some pointers please?
I have been creating a webpage that has a searchbox with a real-time AJAX autosuggest feature, however have come up against a slight problem...
I've managed to get the search function to use a MySQL database to find names similar to the text entered so far... and return the results as a list like this...
Code: Select all
$querySQL = "SELECT DISTINCT Surname FROM `ClientDetails` WHERE Surname LIKE '$nameSearch%'";
$query = mysql_query($querySQL);
while ($row = mysql_fetch_array($query)) {
$LastName .= "<li><a href=\"#\" onClick=\"fillName(this)\">".$row['Surname']."</a></li>";
}
Code: Select all
function fillName(obj) {
document.forms["studentCheck"]["LastName"].value = obj.value;
}
Can anybody give me some pointers please?