Click to See Complete Forum and Search --> : help on this error:document.forms[0].submit() is not a function


gklinux
10-29-2003, 12:34 PM
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

suganya
10-29-2003, 12:42 PM
try
document.getElementById("formname").submit();

suganya

gklinux
10-29-2003, 02:17 PM
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

rjolly
03-13-2007, 04:46 PM
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".

Ultimater
03-14-2007, 02:14 AM
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();

CrazyMerlin
03-14-2007, 02:56 AM
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:

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

Ultimater
03-14-2007, 02:57 AM
Thought I'd also mention you could also do something like this:

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