#1
  1. Rocking my php-ness
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Boston, MA
    Posts
    1,961
    Rep Power
    156

    document.getElementById('someForm').submit() is not a function


    I'm having trouble with a form of mine. It's part of an app built in PHP, but I have some functionality that I use JavaScript for. I have a js function tied to a submit button that assigns a value to a hidden field on submit to tell me if the browser is IE, or Other. Then I use that information with PHP to do some other stuff.

    When you click submit on my form, the correct value gets assigned to the hidden field and the form submits properly. Everything works fine in IE and with FireFox, Opera, etc but if you look at the JavaScript console in FireFox it gives the error:

    document.getElementById('someForm').submit() is not a function

    I don't understand because everything works and the form submits. How could this not be a function? Is it an error with the JavaScript console in FireFox?

    Here's my submit button and part of my JavaScript function:

    PHP Code:
    function submitForm()
    {
        if (
    document.all)
        {
            
    document.getElementById('browser').value 'IE';
        }
        else
        {
            
    document.getElementById('browser').value 'OTHER';
        }
        
    document.getElementById('qform').submit();
    }

    // HTML Submit Button
    <input type="submit" name="submit" onclick="submitForm(); return false;" value="Create URL"/> 
    I hardly use JavaScript anymore other than for toggling CSS attributes and basic rollovers so it's quite possible that I just messed up the submit part. Can someone shed some light on this for me?
    My new WebComic http://www.jjsunshines.com/
    The Geek Shall Inherit the Earth

    It is NOT ok to IM me with questions unless I told you it was ok via PM
  2. #2
  3. Twilight Thinking
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2003
    Location
    Oxford UK
    Posts
    652
    Rep Power
    43
    The form is getting submitted coz a submit button is being clicked.
    document.getElementById('someForm').submit() isn't recognised because, if I remember right, you shouldn't have () at the end.
    Anyway, if you want some js actived when the form is submitted, you need to use:

    onsubmit=someFunction();

    in the form, not 'onclick'.
    Then simply write the function that populates the hidden field. You won't need to try and resubmit using js, so loose document.getElementById('someForm').submit().
    Cheers,
    Dusk

    My portfolio
  4. #3
  5. Rocking my php-ness
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Boston, MA
    Posts
    1,961
    Rep Power
    156
    Thanks for the heads up. I did get it to work without error before making this post but I wanted to get an idea of what was wrong since JavaScript isn't my strong point. In the end I removed the submit from the function and had the submit button return true after the function was called.
    My new WebComic http://www.jjsunshines.com/
    The Geek Shall Inherit the Earth

    It is NOT ok to IM me with questions unless I told you it was ok via PM

IMN logo majestic logo threadwatch logo seochat tools logo