Forum Moderators: open

Message Too Old, No Replies

Submitting a form automatically

But from a specific submit button

         

Robin_reala

3:14 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've got a form with two submit buttons. I'd like to hide the first one using JS and change the associated two radio buttons into automatic submits (which submit when the option is changed). However I can't just call form.submit() as I need to tell the server that the first submit button initiated the submit. Is this even possible?

MisYu

3:37 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



<input type="radio" name="foo" value="bar" onchange="javascript:document.forms["myForm"].submit();" />

if it won't work, do this little tweak:

onchange="javascript:window.setTimeout('document.forms[\"myForm\"].submit();', 50);"

Robin_reala

3:42 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's fine for just submitting a form with a single submit, but here I need to indicate which submit submitted the form...

MisYu

8:31 am on Aug 11, 2006 (gmt 0)

10+ Year Member



If you have <input type="submit"> then, if it has name attribute, you'll get at server which one was clicked. However, if you want to submit the form with something another than submit button and check, what submitted the form, you'll have to catch the value at the server or set a hidden field that will store this information.

Robin_reala

10:39 am on Aug 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That sucks. Oh well, thanks for the help.

Fotiman

2:14 pm on Aug 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




I've got a form with two submit buttons. I'd like to hide the first one using JS and change the associated two radio buttons into automatic submits (which submit when the option is changed). However I can't just call form.submit() as I need to tell the server that the first submit button initiated the submit. Is this even possible?

Can you post some HTML code? I'm not sure what you mean by "associated two radio buttons". Also, is the submit button that you plan to hide with JS sometimes visible? That is, does some other selection on the screen control whether or not this button is visible? If not, and the button is never visible, then you don't need the button at all, do you?

Also, don't forget that if your form has any text inputs, the user can set the focus to one of those and press Enter to submit the form using the first submit button. Not sure if that will be an issue for you.