I am working on a form where a user can select a letter from A - Z to select a list of users whose username begins with that letter.
What i am trying to do is when the user clicks a letter, a php script is called to do a database query that pulls any username which begins with the clicked letter.
I have found this page which has started me off http://openenergymonitor.org/emon/node/107 and also this one which is closer to what i want to do Simple Ajax Jquery script- How can I get information for each of the rows in the table?
What i want to do with the returned results is put them in a SELECT list and also when a user click a different letter, that list contents is replaced with the new query results.
What i'm not sure is how to and if possible pass the letter to the php script so i can search the database for usernames that begin with that letter.
EDIT: I have got it hopefully improved to this but i'm getting Ajax error: ParseError
this is my code so far
<div>
<ul>
<li class="alphabets" id="All">All</li>
<li class="alphabets" id="A">A</li>
<li class="alphabets" id="B">B</li>
<li class="alphabets" id="C">C</li>
<li class="alphabets" id="D">D</li>
</ul>
</div>
<div id="recipients">
$(document).ready(function(){
$("li.alphabets").click(function(){
var the_letter = $(this).text();
alert(the_letter);
$.ajax({
url: 'php/selectuser.php', type: 'GET', data: {'letter':the_letter}, dataType: 'json', success: function(rows) {
var options = '';
for (var i in rows) {
var row = rows[i];
var id = row[0];
var vname = row[1];
options += '<option value="' + id + '">' + vname + '</option>';
}
$("#userlist").html(options);
}
});
});
});
<select id="userslist" name="recipients" size="5">
</select>
</div>