Skip to main content
Known Participant
July 29, 2008
Question

IF CHECK BOX IS CHECKED

  • July 29, 2008
  • 2 replies
  • 1911 views
I have a check box and need the next field (the date) to be filled out if the check box is filled out.

i have four pages, a search page, a results page, a details (update) page and a update validation page. just not sure where or what to put in to make it go. stolen bike information is entered on the details (update) page.
so now where and how do i make the stolen date required if the check box is selected?....lol. also if the box after that can be required if the first two are...lol

As of right now they are updating the information if filled out but if i select the check box it does it without me filling out the date or report number.

thanks in advance for any help you can give me...



    This topic has been closed for replies.

    2 replies

    July 30, 2008
    If you're going to make a field be required based on a client side event (checking a check box), then you have to use javascript.

    Since the stolen date field may be omitted if the checkbox is left empty, you wont want the date field to be required.

    Once the user attempts to submit the form, you will need a function to run to validate if the date field has been entered corresponding to the field with the checkbox. If the date field has not been filled out, then dont submit the form and throw an alert.. If a value exists for the date field while the checkbox is checked, then submit the form.

    If you're unfamiliar with js, then you will have to run all of your validation on the server side, and notify the user of the errors after they have submitted the form.
    Inspiring
    September 18, 2008
    quote:

    Originally posted by: CF_output
    If you're going to make a field be required based on a client side event (checking a check box), then you have to use javascript.



    Also, as I have learned, doing validation on the server is always a good practice. You can add javascript validation for better user interface, but don't neglect the server validation. Reason is, if user disables javascript in his browser, then he can do anything he wants if you don't put a server validation.
    Inspiring
    July 30, 2008
    you can do it in the validation page. in your validation page, check if the checkbox is defined or not and also if the value is true. something like

    <cfif IsDefined("FORM.Stolen") AND FORM.Stolen>

    <cfif Len(FORM.StolenDate) AND IsDate(FORM.StolenDate)>
    do the update
    <cfelse.
    go back to edit page and display message that StolenDate is required

    <cfif>

    <cfelse>

    just do the update

    </cfif>