Forum Moderators: open

Message Too Old, No Replies

Using JavaScrip to submit a form won't work!

Using document.form.submit() won't work, why?

         

Sekka

10:55 am on Jun 26, 2006 (gmt 0)

10+ Year Member



Ok, I am completely baffled here, and I need help! :(

Ok, this is my HTML form,

<form name="add_product" action="" method="post">
<input name="product_id" type="hidden" value="1" />
<input name="submit" type="submit" value="Submit"/>
</form>

And this is my JS,

function product_Add () {
// Submit form
document.add_product.submit();
}

And this is the HTML link that submits the form,

<a href="javascript:product_Add ()">Add</a>

This doesn't work in IE or FF, and with the developer console in FF I get the error "document.add_product.submit is not a function".

For the record, my document type is XHTML transitional.

Thank you.

Iguana

11:06 am on Jun 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try <form id="add_product" name="add_product" ...

Sekka

11:07 am on Jun 26, 2006 (gmt 0)

10+ Year Member



Nope. :(

Also for the record, I've tried a lot of variations, e.g. document.getElementById('add_product').submit(), with no success.

Bernard Marx

11:09 am on Jun 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<input name="[red]submit[/red]" type="submit" value="Submit"/> 

Call the submit button something other than

"submit"
. It is causing a conflict, and overriding the form's
submit
method.

Sekka

11:11 am on Jun 26, 2006 (gmt 0)

10+ Year Member



Worked a charm. Thanking ye kindly.

texmex

4:30 pm on Jun 26, 2006 (gmt 0)

10+ Year Member



The submit button doesn't even need a name. It's unlikely that the form handler is going to need to know what the value of your submit button is, eh?

Bernard Marx

6:59 pm on Jun 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Indeed, and in some cases it's not even sent.