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

Q1199 How can I restrict data entry into two text fields based on two radio buttons?

You are here: irt.org | FAQ | JavaScript | Form | 3.6 | Q1199 [ previous next ]

In HTML4.0 someting like this work:

<html>
<form name="myform">
<input type="radio" name="enable" checked
    onClick="this.form.f1.disabled=false;
             this.form.f2.disabled=true;
             this.form.f1.focus();">
<input type="text" name="f1" value=""
    onKeyUp="if (this.disabled) this.value=''">
<br>
<input type="radio" name="enable"
    onClick="this.form.f1.disabled=true;
             this.form.f2.disabled=false;
             this.form.f2.focus();">
<input type="text" disabled name="f2" value=""
    onKeyUp="if (this.disabled) this.value=''">
</form>

<script language="JavaScript"><!--
document.myform.f1.disabled=false; // initial value for NS
document.myform.f2.disabled=true;  // initial value for NS
//--></script>

</html>

©2018 Martin Webb