Forum Moderators: open

Message Too Old, No Replies

submit() doesnt work

Desperately need help

         

one_mind

6:14 am on Oct 19, 2005 (gmt 0)

10+ Year Member



Hi,

I have the following function which changes a forms action and it should then submit the form.

<script type="text/javascript">
function sub()
{
document.projects.action="form.php";
document.projects.submit();
}
</script>

The action is changed successfully but the form doesn't submit. I get the error generated from the submit() line:

Object doesn't support this property or method.

This code seems to work for others but not me.

Any help would be greatly appreciated.

Thanks

Bernard Marx

11:35 pm on Oct 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check that you haven't given your submit button the name, "submit" (a common mistake)

kaled

9:13 am on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you certain that the projects object is the form?

Try
with (documents.forms[0]) {
action = "form.php";
submit();
}

Kaled.

rocknbil

3:50 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another take is to not reference the form name, reference the form object. This provides you more flexibility and you can pass any form to the function, as in:

<form name="form1" action="" onSubmit="return false;">
<input type="text" name="wysiwyg">
<input type="submit" name="submitButton" onClick="someRoutine(this.form);" value="submit">
</form>

<form name="form2" action="" onSubmit="return false;">
<input type="text" name="wysiwyg">
<input type="submit" name="submitButton" onClick="someRoutine(this.form);" value="submit">
</form>

<script type="text/javascript">
function someRoutine(form) {
alert('form name is '+ form.name);
form.action = (form.name=='form1')?'script1.php':'script2.php';
form.submit();
}
</script>