document.form.submit() does not work??????????????

HI All

Either i am missing the boat somwhere or i am going completely mad.

for some reason i have the following

<form name="form1" action="">

<input type="button" name="button" onClick="document.form1.submit();">

</form>

This does not work, not matter how i do it, even if i put the submit call in a function and call the function from the button the form does not submit.

Anybody have any ideas?

Regards
mwskuzzyAsked:
Who is Participating?
 
ZvonkoConnect With a Mentor Systems architectCommented:
In a form you can simplify your event handler to this:
<form name="form1" action="">

<input type="button" name="button" onClick="this.form.submit();">

</form>

BUT!

It will NOT work if you have this:
<form name="form1" action="">

<input type="button" name="button" onClick="this.form.submit();">

<input type="submit" name="submit" >
</form>

If you have an element in the form with the name "submit" then submit() will not work.
Rename that element to "Submit"

0
 
contactkarthiCommented:
<form name="form1" action="">

<input type="button" name="button" onClick="javascript:document.form1.submit();">

</form>
0
 
Maverick_CoolCommented:
whats ur action url
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
cookiejCommented:
Well, an action might be a good thing to add...!

Two ways to do it.

1)
<form name='form1" action="dosomething.php">
    <input type='submit' name='Submit me, Baby!">
</form>

-or-

function submitTheForm() {
    theForm = document.form1;
    theForm.action = "dosomething,php"
    theForm.submit();
}

...

<form name='form1" action="dosomething.php">
    <input type='submit' name='Submit me, Baby!">
</form>
0
 
mwskuzzyAuthor Commented:
No way! I cant beleive it? I would never have guessed that.

Thanks dude.
0
 
Michel PlungjanIT ExpertCommented:
@cookiej your should be

<script>
function submitTheForm(theForm) {
    theForm.action = "dosomething.php"
    theForm.submit();
}
</script>
...

<form name='form1" action="dosomething.php">
    <input type='button' onClick="submitTheForm(this.form)" name='Submit me, Baby!">
</form>
alternatively
<a href="#" onClick="submitTheForm(document.form1); return false">Submit me, Baby!</a>
0
All Courses

From novice to tech pro — start learning today.