• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

cfinput validation with text and checkbox with JS (passing values & disable)

I have a text box and a check box. Right now I have the code working for when teh checkbox is click the textbox is disabled. But I want the the checkbox to give the text box a value of -888 if the checkbox is CLICKED. I do not want the value to SHOW UP IN THE TEXT BOX! I just want to pass it to the action page to insert -888 in the database if they do not know.  The big thing is I want to keep my CFinput validation!
Can I do this still? Right now the textbox is not getting the value because I'm clearing it out. I need th action page to get that value but it's reading no response it should say don't know. HELP!

<cfif recinj is -888><cfset DK=""><cfelse><cfset DK=recinj></cfif>

<cfinput  type="text" name=recinj  validate="float" validateat="onsubmit" message="Please enter numbers only, in Total Recordables" size="15" maxlength="20" value="#DK#"> Total Recordables <br>

<INPUT name="recinj2" type=checkbox Value="-888" onClick="setValue(this.name,'recinj')" <cfif recinj is -888>checked</cfif>>Don't know</td>

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">

      function setValue(strCheckName,strTextName){
     var objFormField = document.forms[0]
     if(objFormField.elements[strCheckName].checked){
          objFormField.elements[strTextName].value= "";
          objFormField.elements[strTextName].disabled=true;
     }else{
          objFormField.elements[strTextName].value="";
          objFormField.elements[strTextName].disabled=false;
     }

}

</SCRIPT>
0
FIATECH
Asked:
FIATECH
  • 10
  • 8
1 Solution
 
FIATECHAuthor Commented:
I forgot to mention that the checkbox needs to stay clicked upon revisted or the value is changed! Right now it won't stay checked after I saved
0
 
James RodgersWeb Applications DeveloperCommented:
put this in the form processing page
<cfif isDefined('form.recinj2')>
      <cfset insertValue=#form.recinj2#>
<cfelse>
      <cfset insertValue=#form.recinj#>
</cfif>

and change teh inserted value in teh query from  recinj to insertValue
0
 
FIATECHAuthor Commented:
OK I'll try that. FYI recinji is the only define variable in the DB
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
FIATECHAuthor Commented:
That didn't work and it still says No response in the action page.

This is what I have in that action page:
<cfif isDefined('form.recinj2')>
      <cfset insertValue=#form.recinj2#>
<cfelse>
      <cfset insertValue=#form.recinj#>
</cfif>
<cfif recinj is -888><font color="##FF0000"> <strong>Don't Know </strong></font><cfelseif recinj is ""> <font color="##FF0000"> <strong>No Response</strong> </font> <cfelse>#recinj#</cfif>
0
 
James RodgersWeb Applications DeveloperCommented:
this
<cfif isDefined('form.recinj2')>
      <cfset insertValue=#form.recinj2#>
<cfelse>
      <cfset insertValue=#form.recinj#>
</cfif>
is supposed to go in teh page that performs teh data insert
0
 
FIATECHAuthor Commented:
Yes I know. In the action page. I have my query insert and update on this page
0
 
James RodgersWeb Applications DeveloperCommented:
did you do a cfdumpo to see what teh form contains?

<cfdump var=#form#">
does it show
recinj2
recinj
?
0
 
FIATECHAuthor Commented:
It says Variable RECINJ2 is undefined. in both pages!
0
 
James RodgersWeb Applications DeveloperCommented:
so it is not listed in the dump? then there is something wrong with the form, a text input should always be defined in a form even if it has no value, unless it is disables, in which case you should se teh checkbox name in teh dump
0
 
FIATECHAuthor Commented:
Ok I had to change this  value="#DK#" to  value="#recinj#">

But the dump came back empty string

<cfif recinj is -888><cfset DK=""><cfelse><cfset DK=recinj></cfif>

<cfinput  type="text" name=recinj  validate="float" validateat="onsubmit" message="Please enter numbers only, in Total Recordables" size="15" maxlength="20" value="#DK#"> Total Recordables <br>

<INPUT name="recinj2" type=checkbox Value="-888" onClick="setValue(this.name,'recinj')" <cfif recinj is -888>checked</cfif>>Don't know</td>

0
 
FIATECHAuthor Commented:
I got values now for recinj2 (-888) but when I go back, the checkbox is not check because it's checking against the recinj and not the recinj2
0
 
James RodgersWeb Applications DeveloperCommented:
try this
<INPUT name="recinj2" type=checkbox Value="-888" onClick="setValue(this.name,'recinj')" <cfif not DK>checked</cfif>>Don't know</td>
0
 
FIATECHAuthor Commented:
I tried and got this: cannot convert the value "" to a boolean

I don't think I can do this  <cfif not DK>checked</cfif>>??
0
 
James RodgersWeb Applications DeveloperCommented:
>>I don't think I can do this  <cfif not DK>checked</cfif>>??
no, try this instead

<cfif not trim(DK) EQ ''>checked</cfif>>??
0
 
FIATECHAuthor Commented:
No error this time but no saved check
0
 
James RodgersWeb Applications DeveloperCommented:
it might be backwards
<cfif trim(DK) EQ ''>checked</cfif>
0
 
FIATECHAuthor Commented:
I changed it to and THAT SO WORKED!!!THANKS! I'm so happy!
0
 
James RodgersWeb Applications DeveloperCommented:
glad i could help

thanks for the points
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now