We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    To mix metaphores, I’ve jumped into the deep end here, with AJAX, before I’ve ever done much at all with Javascript. Now, I’m trying to do a simple, obvious, rank-beginner thing and it just doesn’t work! Here’s the very simple code:

    function checkSubmit(theForm) {
        var myForm = document.getElementById(theForm);
        if(myForm.sbName.value == '') {
            alert('Need to enter a name!');
            return false;
        } else if(myForm.sbMessage.value == '') {
            alert('Need to enter a message!');
            return false;
        } else {
            document.myForm.submit();
        }
    }
    


    It’s called on the onClick event of a button element. The form has the same ID and name values. The input value checks work perfectly, but the submit just doesn’t work! I fiddle with it, and get one of two errors: document.myForm has no properties, or: document.the SpecificFormName.submit is not a function. I’ve tried it as document.forms.theForm... document.forms.theSpecificFormName... every permutation I can think of, and it’ either the "no properties" or "not a function" error.

    I’ve been three days reading I-don’t-know-how-many tutorials and sample scripts, and they all say the same thing, and at least I THINK I’m doing the same thing. Any ideas huh
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 4018
      • 1,131 Posts
      If you could, attach the page as a zip file and I’ll be glad to look at it. I’ve been getting back into doing some javascript as well so...it’ll be a learning experience for me as well. smiley

      L8R!

      Jeff

      Quote from: sottwell at Jun 25, 2005, 01:21 AM

      To mix metaphores, I’ve jumped into the deep end here, with AJAX, before I’ve ever done much at all with Javascript. Now, I’m trying to do a simple, obvious, rank-beginner thing and it just doesn’t work! Here’s the very simple code:

      function checkSubmit(theForm) {
          var myForm = document.getElementById(theForm);
          if(myForm.sbName.value == '') {
              alert('Need to enter a name!');
              return false;
          } else if(myForm.sbMessage.value == '') {
              alert('Need to enter a message!');
              return false;
          } else {
              document.myForm.submit();
          }
      }
      


      It’s called on the onClick event of a button element. The form has the same ID and name values. The input value checks work perfectly, but the submit just doesn’t work! I fiddle with it, and get one of two errors: document.myForm has no properties, or: document.the SpecificFormName.submit is not a function. I’ve tried it as document.forms.theForm... document.forms.theSpecificFormName... every permutation I can think of, and it’ either the "no properties" or "not a function" error.

      I’ve been three days reading I-don’t-know-how-many tutorials and sample scripts, and they all say the same thing, and at least I THINK I’m doing the same thing. Any ideas huh
        Jeff Whitfield

        "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
        • 30481
        • 33 Posts
        Old post, but i have the same problem in a modx context...

        the document.getElementById function didn’t seems to work...

        I have always a document.myForm has no properties

        Same thing if i try to acces it by document.all.myForm
          -------------------------------
          www.fabienletort.com
          • 4018
          • 1,131 Posts
          Although this is a real cope out, one thing you might try is utilizing the mootools library (/manager/media/script/mootools/mootools.js). It’ll allow you to do things that are much similar to what Prototype allows you to do. For instance, using the document.getElementById function might look something like this:

          var div = document.getElementById('myElement');
          


          But with mootools we can assign an element with a ID using a much simpler method:

          var div = $('myElement') // gets a DOM element by id with all the Element prototypes applied.
          


          There’s also a getValue method that comes in handy for getting the value of a textarea, select or input element. Let’s say you have a text box with an ID of ’textboxExample’ then you could assign the value of it to a variable like this:

          var example = $('textboxExample').getValue();
          


          All in all, mootools provides some excellent ways of writing custom code that is leaner, cleaner and simply gets the job done. Check it out! smiley

          More information about the properties of the Elements.js functions in mootools can be found in the mootools docs (http://docs.mootools.net/files/Native/Element-js.html). There’s also a great tutorial site (http://clientside.cnet.com/wiki/mootorial/) for mootools as well.

          Jeff
            Jeff Whitfield

            "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."