Skip to main content
Inspiring
April 18, 2007
Question

Radio Buttons

  • April 18, 2007
  • 2 replies
  • 394 views
In my cfform, I have two radio button (yes and no) and an entry field. The no is prechecked so that it is the default. If the user decides to check yes, then I need to make the entry field a required entry, otherwise it remains blank. How do I edit/validate that ? Here is what I have so far :

<cfinput type="radio" name='button_1" value="Yes">Yes
<cfinput type="radio" name="button-2" value="No" checked> No
<br>
<cfinput type='text" name="field_1" value=" ">
    This topic has been closed for replies.

    2 replies

    April 19, 2007
    if ( testFrm.button_1[0].checked == true && testFrm.field_1.value == '') {
    alert("Please fill in the field below.");
    }

    April 18, 2007
    some javascript that's similar to this:

    if form.button_1.checked == true && form.field_1.value == "" {
    alert("Please fill in Field 1");
    }
    trojnfnAuthor
    Inspiring
    April 19, 2007
    I made a mistake in my oringal code, both names should be the same :

    <cfinput type="radio" name='button_1" value="Yes">Yes
    <cfinput type="radio" name="button_1" value="No" checked> No
    <br>
    <cfinput type='text" name="field_1" value=" ">

    Now using the javascript validation sample, it will always be true, since the box is always checked as No for the default. If the yes box is checked, then the field field_1 becomes should be required. How can I do that ?