Ajax issue
-
Ok I'm trying to learn this and I'm running into a problem and I'm not sure why... I'm going through a tutorial on tizag and I'm getting a error for the onChange event. This is the code:
<html>
<body><script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ document.myForm.time.value = ajaxRequest.responseText; } } ajaxRequest.open("GET", "serverTime.php", true); ajaxRequest.send(null);
}
//-->
</script><form name='myForm'>
Name: <input type='text' onChange="ajaxFunction();" name='username' /> <br />
Time: <input type='text' name='time' />
</form>
</body>
</html>the error message is "Object expected at JScript - myForm onchange function() (/IntranetSite/order.html:47) Thanks in advance!!
-
Ok I'm trying to learn this and I'm running into a problem and I'm not sure why... I'm going through a tutorial on tizag and I'm getting a error for the onChange event. This is the code:
<html>
<body><script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ document.myForm.time.value = ajaxRequest.responseText; } } ajaxRequest.open("GET", "serverTime.php", true); ajaxRequest.send(null);
}
//-->
</script><form name='myForm'>
Name: <input type='text' onChange="ajaxFunction();" name='username' /> <br />
Time: <input type='text' name='time' />
</form>
</body>
</html>the error message is "Object expected at JScript - myForm onchange function() (/IntranetSite/order.html:47) Thanks in advance!!
Have you debugged? Once you have you will be able to find the issue easily. I would use JQuery and do away with this mess of nested try/catch blocks
No comment
-
Have you debugged? Once you have you will be able to find the issue easily. I would use JQuery and do away with this mess of nested try/catch blocks
No comment
yes that is where I got the error message from (the debugger)... I'm just trying to learn how to get a JavaScript app to work with a database and this was the first part of the tutorial. If you have any better ideas I'm open to them as I haven't invested too much into this one yet :) Does onChange="ajaxFunction();" need to be single quote?
-
yes that is where I got the error message from (the debugger)... I'm just trying to learn how to get a JavaScript app to work with a database and this was the first part of the tutorial. If you have any better ideas I'm open to them as I haven't invested too much into this one yet :) Does onChange="ajaxFunction();" need to be single quote?
MacRaider4 wrote:
Does onChange="ajaxFunction();" need to be single quote?
Wouldn't it be faster to test that theory yourself rather than ask if that's the solution and wait for an answer?
EOL
-
MacRaider4 wrote:
Does onChange="ajaxFunction();" need to be single quote?
Wouldn't it be faster to test that theory yourself rather than ask if that's the solution and wait for an answer?
EOL
I tried it that way and it made no difference, but I was wondering as I would like to learn the "right way"... forgot to mention that in my reply sorry
-
I tried it that way and it made no difference, but I was wondering as I would like to learn the "right way"... forgot to mention that in my reply sorry
I typically favor using double quotes, though single quotes would work too. When working with ASP.net, I find it easier to sometimes use single quotes, as binding often makes use of double quotes (and having double quotes inside double quotes can cause errors).
EOL
-
I typically favor using double quotes, though single quotes would work too. When working with ASP.net, I find it easier to sometimes use single quotes, as binding often makes use of double quotes (and having double quotes inside double quotes can cause errors).
EOL
Coming from an application background this web stuff is a bit hard to get used to, but doesn't seem too bad all in all. Though it would be nice if you didn't have to go about things in a round about manner. Back to the original issue, it seems like the function call wants something in the () however I don't have anything specified in the function it self so that doesn't make sense.
-
Coming from an application background this web stuff is a bit hard to get used to, but doesn't seem too bad all in all. Though it would be nice if you didn't have to go about things in a round about manner. Back to the original issue, it seems like the function call wants something in the () however I don't have anything specified in the function it self so that doesn't make sense.
Ok I've found it... simple mistake I guess...
</pre>
vs
<pre lang="Javascript"><script type="txt/javascript"></pre>
forgot the 'e' in text.... :omg:</x-turndown> -
I tried it that way and it made no difference, but I was wondering as I would like to learn the "right way"... forgot to mention that in my reply sorry
HTML attributes should be enclosed in double quotes, as it's part of the same family as XML. Most browsers will tolerate all sorts of bad markup but to do it right is to use doubles there. Quotes within Javascript can be either, as long as they are paired with the same type, and either is fine in any situation.
-
HTML attributes should be enclosed in double quotes, as it's part of the same family as XML. Most browsers will tolerate all sorts of bad markup but to do it right is to use doubles there. Quotes within Javascript can be either, as long as they are paired with the same type, and either is fine in any situation.
Well if double is the standard then I'll go with double. Thanks for the help!!