Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Ajax issue

Ajax issue

Scheduled Pinned Locked Moved JavaScript
helpjavascriptphphtmlsysadmin
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MacRaider4
    wrote on last edited by
    #1

    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!!

    N 1 Reply Last reply
    0
    • M MacRaider4

      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!!

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • N Not Active

        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

        M Offline
        M Offline
        MacRaider4
        wrote on last edited by
        #3

        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?

        A 1 Reply Last reply
        0
        • M MacRaider4

          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?

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • A AspDotNetDev

            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

            M Offline
            M Offline
            MacRaider4
            wrote on last edited by
            #5

            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

            A B 2 Replies Last reply
            0
            • M MacRaider4

              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

              A Offline
              A Offline
              AspDotNetDev
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • A AspDotNetDev

                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

                M Offline
                M Offline
                MacRaider4
                wrote on last edited by
                #7

                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.

                M 1 Reply Last reply
                0
                • M MacRaider4

                  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.

                  M Offline
                  M Offline
                  MacRaider4
                  wrote on last edited by
                  #8

                  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>

                  1 Reply Last reply
                  0
                  • M MacRaider4

                    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

                    B Offline
                    B Offline
                    BobJanova
                    wrote on last edited by
                    #9

                    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.

                    M 1 Reply Last reply
                    0
                    • B BobJanova

                      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.

                      M Offline
                      M Offline
                      MacRaider4
                      wrote on last edited by
                      #10

                      Well if double is the standard then I'll go with double. Thanks for the help!!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups