Hi,
The test page at http://www.soundset.com/test.php is intended to perform client side validation and to display a message to the user if it fails. It uses a variable with getElementById(var) so the form can be expanded later and the message displayed in different divs.
The trouble seems to be when the error check is triggered. The div named in the variable is 'not defined' according to the Firefox error console.
Here is the content of test.php:
Here is the content of getClue.php:HTML Code:<!DOCTYPE html> <html dir="ltr" lang="en-US"> <head> <meta charset="iso-8859-1" /> <title>test</title> <script type="text/javascript"> function GetXmlHttpObject() { var req; try { // Firefox, Opera, Safari req = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { //For IE 6 req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { //For IE 5 req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera'); } } } return req; } </script> <script type="text/javascript"> var xmlHttp function show_hint(field, str, hintBox) { if (str.length==0) { document.getElementById(hintBox).innerHTML="" return } xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="http://www.soundset.com/getClue.php" url=url+"?q="+str url=url+"&field="+field xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById(hintBox).innerHTML=xmlHttp.responseText } else { document.getElementById(hintBox).innerHTML="<img src=images/ajax-loader.gif></img>"; } } </script> </head> <body> <br /><br /> <form action="test.php" method="post"> Qty: <input name="quantity" value="" onblur="show_hint('quantity', this.value, 'txtHint')" type="text" /> <div id="txtHint"> </div> </form> </body> </html>
Why would hintBox be undefined? Thanks!PHP Code:$field = $_GET['field'];
$q = $_GET['q'];
if($field == 'quantity')
{
if($q < 1)
{
$hint = 'Quantity must be at least 1.';
}
if($q > 100)
{
$hint = 'Quantity cannot be greater than 100.';
}
if(!is_numeric($q))
{
$hint = 'Quantity must be numeric.';
}
if($q > 1 AND $q < 100 AND is_numeric($q))
{
$hint = 'OK';
}
}
$response = $hint;
//output the response
echo $response;


LinkBack URL
About LinkBacks



Reply With Quote
). It's just the random name I gave to my div to display the result.

Bookmarks