Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Form 7.2 | Q579 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.