Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfif based on checkbox

Participant ,
Mar 04, 2008 Mar 04, 2008
I have a form with the following fields :

<cfinput type="text" name="return_to_supplier_supplier_number" onValidate="validateOptionTextBox" message="Supplier number is required">

<cfinput type="checkbox" name="not_valid_supplier" value="NVS"> Not a Valid Supplier

The input field is required and the onValidate part does work, diplaying the error message if I leave it blank. However, if they check the checkbox, then the input field becomes optional. What I would like to do is put a cfif around the onvalidate based on the checkbox. If the checkbox is check, then do not validate, if it is unchecked, then validate.

How can that be done, or this there a better way ? Thanks
797
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 04, 2008 Mar 04, 2008
Are these fields in a flash form or html form ?

If a flash form:

Create an action script function that would turn off the validation and make the form field not visible.
This function would then be activated by the user clicking the checkbox

If a html form:
Then you will need to do the same thing in javascript.

Ken
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 04, 2008 Mar 04, 2008
It is an html form.

I was hoping to avoid java. There is some other java code for other things and when I tried to add this, they seem to clobber each other, so I was hoping there was a way to do it without java
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 04, 2008 Mar 04, 2008
quote:

Originally posted by: trojnfn
I have a form with the following fields :

<cfinput type="text" name="return_to_supplier_supplier_number" onValidate="validateOptionTextBox" message="Supplier number is required">

<cfinput type="checkbox" name="not_valid_supplier" value="NVS"> Not a Valid Supplier

The input field is required and the onValidate part does work, diplaying the error message if I leave it blank. However, if they check the checkbox, then the input field becomes optional. What I would like to do is put a cfif around the onvalidate based on the checkbox. If the checkbox is check, then do not validate, if it is unchecked, then validate.

How can that be done, or this there a better way ? Thanks

You can't mix cfml and javascript. They run on different computers. You have to do it all in javascript. I suggest calling your function when you submit your form. Also, it will all be much simpler with form instead of cfform.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 09, 2008 Mar 09, 2008
LATEST
function chkForm()
{
var t = document.getElementById("myTextBox");
var c = document.getElementById("myCheckBox");
if (! c.checked)
{
if (t.value = "")
{
alert("Supplier number is required");
t.focus();
return false;
{
}
return true;
}

onSubmit = "chkForm()"
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources