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...
IN MY DETAILS (update) page...
<tr>
<td><div align="center">
<input type="checkbox" name="Stolen" value="true" >
</div></td>
<td><div align="center">
<cfinput type="text"
validate="date"
name="StolenDate"
value="#LSDateFormat(BikeResult.StolenDate,'M/DD/YY')#"
message="You Must Enter a Valid Issue Date ie. 7/21/2008">
</div></td>
<td><div align="center">
<cfinput type="text"
name="StlnRMSNum"
value="#Trim(BikeResult.StlnRMSNum)#"
message="You Must Enter the CrisNet Report Number">
</div></td>
dongzky - 30 Jul 2008 13:48 GMT
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>
CF_output - 30 Jul 2008 18:46 GMT
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.
dongzky - 18 Sep 2008 13:47 GMT
[q][i]Originally posted by: [b][b]CF_output[/b][/b][/i]
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.
[/q]
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.