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

Q579 How do I change the action property of a form based on which radio button is checked?

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

This will not work on Internet Explorer 3 as it the forms action property is read only. Therefore its better to have one form per radio button - with only one visible submit button:

<html>
<head>
<script language="JavaScript"><!--
function go(what) {
    for (var i=0;i<3;i++) {
        if (what.page[i].checked) {
            document.forms[what.page[i].value].submit();
        }
    }
}
//--></script>
</head>

<body>

<form action="page1.htm" target="targetframename" name="page1"><input type="hidden" value="page1"></form>
<form action="page2.htm" target="targetframename" name="page2"><input type="hidden" value="page2"></form>
<form action="page2.htm" target="targetframename" name="page3"><input type="hidden" value="page3"></form>

<form>
Page 1: <input type="radio" name="page" value="page1">
Page 2: <input type="radio" name="page" value="page2">
Page 3: <input type="radio" name="page" value="page3">
<p>
<input type="button" onClick="go(this.form)" value="Submit">
</form>

</body>
</html>

Feedback on 'Q579 How do I change the action property of a form based on which radio button is checked?'

©2018 Martin Webb