0

I'm trying to create a jQuery script that will allow me to implement livesearch. So far, all I've got on the screen is nothing, nothing is showing up and I have no idea what's wrong. Any ideas?

javascript:

function searchMembers() {
    document.body.style.cursor = "wait";
    var gradeMenu = document.getElementById("grade");
    var gradeValue = gradeMenu.options[gradeMenu.selectedIndex].text;
    var firstNameValue = document.getElementById("firstName").value;
    var lastNameValue = document.getElementById("lastName").value;
    var studentIDValue = document.getElementById("studentID").value;

     $.post (
           "search.php", 
           {'firstName':firstNameValue, 'lastName':lastNameValue,  'grade':gradeValue, 'stID':studentIDValue},
           function(data) {
                 document.getElementById("searchOutput").innerHTML=data;
                 document.body.style.cursor="auto";
            }
      );
}
$(document).ready(function() {
      var loc = (String)(window.location);
          if(loc.indexOf("view_membersWithSearch.php") > 0)
      searchMembers();
 });

search.php:

   if(isset($_POST['firstName'])) {
        $firstNameValue = $_POST['firstName'];  
    }
    if(isset($_POST['lastName'])) {
        $lastNameValue - $_POST['lastName'];
    }       
    if(isset($_POST['grade'])) {
        $gradeValue = $_POST['grade'];
    }
    if(isset($_POST['stID'])) {
        $studentIDValue = $_POST['stID'];
    }   

view_membersWithSearch.php:

<div id="searchOutput"></div>

Edit: jQuery is included, I placed it at the bottom of view_membersWithSearch.php. The problem is after I click on a menu or insert text to update the search, nothing happens. The area where the results are supposed to be placed is blank. By default, I'm also supposed to have all the results displayed by default, but that too is blank.

Edit 2: Firebug gives this: The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol.

Andrew
  • 3,501
  • 8
  • 35
  • 54

1 Answers1

0
$.post (
           "search.php", 
           {firstNameValue:'firstName', lastNameValue:'lastName',  gradeValue:'grade', studentIDValue:'stID',

EDIT 1:

$.post (
           "search.php", 
           {firstName:firstNameValue, lastName:lastNameValue,  grade:gradeValue, stID:studentIDValue},

Edit 2:

You missed href

    if(loc.href.indexOf.("view_membersWithSearch.php") > 0)
Amir
  • 4,089
  • 4
  • 16
  • 28
  • `'firstName':firstNameValue` to `firstNameValue:'firstName'` and so on – Amir Mar 23 '13 at 08:21
  • That's not right, @Andrew. You *don't* need the quotes around your object literal labels (as they are in your question), but this is just getting that syntax confused with JSONish syntax. There's no reason to switch the variables to the labels, and isn't valid as it is (as I think it will cause a `SyntaxError`. – Jared Farrish Mar 23 '13 at 08:23
  • The second is Javascript an object initializer in it's *literal* syntax. However, quoting the labels on an object literal is 100% valid. – Jared Farrish Mar 23 '13 at 08:27