-2

This code finds a scu in a database and displays it as you are typing. It works in all browsers(chrome, IE, opera) except for firefox. If anyone can see why i would greatly appreciate the help.

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script src="chData_test.js"></script>

</head>
<body>
<form name="testForm">
<input type="text" name="scu" id="scu"><input type="button" id="theButton">
</form>
<div id="output"></div>
</body>

$(document).ready(function() {
  $('#theButton').click(get);
  $('#scu').keyup(get);
  function get() {
    $.post('data.php', {scu:testForm.scu.value}, function(output) {
      $('#output').text(output).show();
    });
  }
});

<?php
mysql_connect("***.000webhost.com", "a9414387_***", "****");
$scu = mysql_real_escape_string($_POST['scu']);

if ($scu==NULL) {
echo "No entry scu found";
}
else {
$description = mysql_query("SELECT description FROM a9414387_***.inventory WHERE id LIKE '$scu%'");
$description_num_rows = mysql_num_rows($description);
if ($description_num_rows==0) {
echo "scu not found in database";
}
else {
$description = mysql_result($description, 0);
echo "You have selected the $description";
}
}

?>
Blazemonger
  • 90,923
  • 26
  • 142
  • 180
user1114060
  • 117
  • 2
  • 7
  • 5
    In what way does it not work? – Blazemonger Jun 01 '12 at 16:05
  • 1
    Look at the JavaScript console? Are there any errors? Look at the HTTP request. Is the data what you expect. Look at the PHP logs. Are there any errors? Look at the SQL being generated. Is it what you expect? Look at the HTTP response the PHP is making. Is it what you expect? *Don't just say "it isn't working"* – Quentin Jun 01 '12 at 16:06
  • It does not seem to connect to the php file. Nothing happens when i type in #'s. – user1114060 Jun 01 '12 at 16:07
  • "Look at the JavaScript console? Are there any errors? Look at the HTTP request. Is the data what you expect" – Ashley Davies Jun 01 '12 at 16:09
  • 1
    MySQL and PHP have nothing to do with your browser... Use Firebug console to have some details about the errors that might occurs in your jQuery code. – AsTeR Jun 01 '12 at 16:09
  • There are [a few](http://stackoverflow.com/q/7996449/901048) [questions](http://stackoverflow.com/questions/2511205/keyup-bindings-not-working-in-firefox) on SO already relating to keyup and firefox. See if they help. – Blazemonger Jun 01 '12 at 16:09
  • try to put the php tag inside the body tag () – jcho360 Jun 01 '12 at 16:09
  • Not sure if this is causing the problem, but you are missing Script tags around your javascript – ckaufman Jun 01 '12 at 16:16
  • Try also to put your javascript just after `` and into `` – Franquis Jun 01 '12 at 16:17
  • 1
    There is too much wrong here for your code to work in **any** browser. There is no way the above works in IE. Please post your actual "working" code. – user229044 Jun 01 '12 at 16:21
  • Sorry for all the confusion. It's 3 separate files. I'm at my works' pc which doesn't have firebug or much of anything on it. I got to another pc and it is throwing an "testForm is not defined" error. Also, i just forgot to remove .click function. – user1114060 Jun 01 '12 at 16:49

2 Answers2

1

true to use instead of "testForm.scu.value" -> "$('#scu').val()", for example:

function get() {
  var postdata = $('#scu').val();
    $.post('data.php', {scu:postdata}, function(output) {
      $('#output').text(output).show();
    });
  }
Bob
  • 128
  • 1
  • 6
0

try defining "function get" before you reference it.

$(document).ready(function() {
  function get() {
    $.post('data.php', {scu:testForm.scu.value}, function(output) {
      $('#output').text(output).show();
    });
  }
  $('#theButton').click(get);
  $('#scu').keyup(get);
});
Roman
  • 5,888
  • 26
  • 47
  • this didn't work, but i think it has something to do with the way scu:testForm.scu.value is set up. b/c it is throwing an "testForm is not defined" error. – user1114060 Jun 01 '12 at 17:13