OK so I’m doing a “quick search” kind of thing. I have jQuery GET request everytime a field on a form changes but it’s not working. I have provided an SSCCE.
Don’t worry about the AJAX call because the thing that’s not working is the request. For example, if I tick 19, the GET request will STILL be Pick one.
Here it is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Untitled 3</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function() {
var test = $(".age1").val();
alert(test);
var dataString = "test=" + test;
$("#formtest").live("change", function() {
$.ajax({
type: "GET",
url: "quick_search.php",
data: dataString,
cache: false,
success: function(html) {
$("#display").after(html);
}
});
});
return false;
});
</script>
</head>
<body>
<form action="quick_search.php" id="formtest" method="GET">
live GET
<select class="age1" name='age1'>
<option value='Pick One'>- Pick One -</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
</select>
</form>
<div id="display"></div>
</body>
</html>
you need to change the value of
dataStringevery time the value changes. Currently you are only changing it on page load, therefore it never changes after.