dcsimg
www.webdeveloper.com
Results 1 to 7 of 7

Thread: help on this error:document.forms[0].submit() is not a function

  1. #1
    Join Date
    Oct 2003
    Posts
    2

    help on this error:document.forms[0].submit() is not a function

    hi,

    i'm working on a form which has an image button like this:
    <img src= \"next.gif\" alt = \"next\" onClick=goSave(0);>

    basically there are multiple forms.

    my goSave function looks like this:
    function goSave(page) {
    document.forms[page].action= \"http://66.36.242.93/test123/testfiles/ccprform.php?pageno=2\";
    document.forms[0].submit();
    }

    i get a javascript error :
    document.froms[0].submit() is not a function.

    no error with
    document.forms[0].action , though.

    I'm doing these as an upgrade to an almost finished project, only this is stopping me.


    thanks in advance,

    gklinux

  2. #2
    Join Date
    Jun 2003
    Location
    woodbury, MN
    Posts
    48
    try
    document.getElementById("formname").submit();

    suganya

  3. #3
    Join Date
    Oct 2003
    Posts
    2
    syganya,

    the reason i'm trying something like this is because
    my script doesn't know a form name until
    a button is clicked.
    i want to be able to submit the form
    in which the button exists.

    why doesn't document.forms[0].submit() work?

    the solution you have suggested needs the name of the form hardcoded, which i don't want to do.

    i'm sure someone must have done this before!

    thanks,

    gklinux

  4. #4
    Join Date
    Mar 2007
    Posts
    1

    possible conflicting element name

    For anyone interested, "document.forms[0].submit();" will not work if any form elements are named "submit". Probably the original poster named the submit button "submit".

  5. #5
    Join Date
    Jan 2005
    Location
    San Diego, CA
    Posts
    4,887
    Code:
    if(typeof document.forms[0].submit=="function")
    document.forms[0].submit();
    else if(typeof document.forms[0].submit.click=="function")
    document.forms[0].submit.click();

  6. #6
    Join Date
    Dec 2005
    Location
    Queen Creek, AZ
    Posts
    1,564
    first of all...why all the escaping the quotes?

    second, if you want a button, a real button but with an image, use a real button and set:
    Code:
    <input type="submit" style="background:url(IMAGE_LOCATION) no-repeat; border: 0px;".....
    that way at least you have a real button!

    now, if your button is within the <form></form> tags, then it is a form element, which mens that Button.form relates to the parent. You never actually need to know the forms name.
    Last edited by CrazyMerlin; 03-14-2007 at 03:02 AM.
    Design first! Code later!

  7. #7
    Join Date
    Jan 2005
    Location
    San Diego, CA
    Posts
    4,887
    Thought I'd also mention you could also do something like this:
    Code:
    document.forms[0].appendChild(document.createElement("button")).click();
    Just in case you are using <input type="button" name="submit"> rather than <input type="submit" name="submit">

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles