Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q378 How can I have two submit buttons with different actions in one form?

You are here: irt.org | FAQ | JavaScript | Form | 7.2 | Q378 [ previous next ]

It can be done but not in all browsers. Netscape Navigator 3+ or Internet Explorer 4+ is required, as in earlier browsers the action property is read only. Hence the quick and dirty check for the image object:

<script language="JavaScript"><!--
function sendForm(action,encoding) {
    if (document.images) {
        document.registerForm.action = action;
        document.registerForm.encoding = encoding;
    }
    return true;
}
//--></script>

<form name="registerForm">
<input type="text" name="myText" value="some text">
<input type="submit" value="Submit1" onClick="sendForm('/cgi-bin/userform.cgi','text/plain')">
<input type="submit" value="Submit2" onClick="sendForm('mailto:someone@somewhere.com','text/plain')">
</FORM>

Feedback on 'Q378 How can I have two submit buttons with different actions in one form?'

©2018 Martin Webb