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

Q91 It is possible to activate a text input type box when one of two radio button is checked?

You are here: irt.org | FAQ | JavaScript | Form | 10.1 | Q91 [ previous next ]

The best you can do is trap the onFocus event handler to Blur the form field:

<script language="JavaScript"><!--
function firmFocus() {
    if (document.blurForm.testRadio[0].checked)
        document.blurForm.firmText.focus();
    else {
        if (document.blurForm.testRadio[1].checked)
            document.blurForm.personText.focus();
        else
            document.blurForm.firmText.blur();
    }
}

function personFocus() {
    if (document.blurForm.testRadio[1].checked)
        document.blurForm.personText.focus();
    else {
        if (document.blurForm.testRadio[0].checked)
            document.blurForm.firmText.focus();
        else
            document.blurForm.personText.blur();
    }
}

function firmOn(object) {
    firm = true;
    person = false;
    object.personText.value = '';
    document.blurForm.firmText.focus();
}

function personOn(object) {
    firm = false;
    person = true;
    object.firmText.value = '';
    document.blurForm.personText.focus();
}
//--></script>

<table>
<form name="blurForm">
<tr>
<td>Firm:</td>
<td><input type="text" name="firmText" onFocus="firmFocus()">
<input type="radio" name="testRadio" onClick="firmOn(this.form)">
</td>
</tr><tr>
<td>Person:</td>
<td><input type="text" name="personText" onFocus="personFocus()">
<input type="radio" name="testRadio" onClick="personOn(this.form)">
</td>
</tr>
</form>
</table>

<script language="JavaScript"><!--
document.blurForm.firmText.value = '';
document.blurForm.personText.value = '';
//--></script>

©2018 Martin Webb