function not working

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
scifirocket
Forum Commoner
Posts: 31
Joined: Fri Aug 13, 2010 1:24 am

function not working

Post by scifirocket »

I have this function that is supposed to grab entries from a database using PHP and SQL and show results as the user types:

Code: Select all

$(document).ready(function() {
   $("searchb").change(function () {
      $.post("searchtest.php", {partialName: $(this).val()},function(data) {
         $("#results").html(data);
      });
   });  
});
this code references this text field:
[text]<p class="em_text"> <input id="searchb" type="text"/></p>[/text]

i ran firebug, and it reports no errors. what could be the problem?
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: function not working

Post by cpetercarter »

You have given your input field an id "searchb", but no name attribute. Surely the field requires a "name", otherwise the form of which it is part will be unable to submit the contents of the field as GET or POST data. Your jQuery code $('searchb') is looking for an element with the name 'searchb', not one with an id 'searchb'. If you want the latter, you need $("#searchb"). But, as I say, I think that adding name="searchb" to the input field is probably what you intended to do.
Post Reply