Link to home
Start Free TrialLog in
Avatar of FIATECH
FIATECH

asked on

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>
Avatar of FIATECH
FIATECH

ASKER

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
Avatar of James Rodgers
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
Avatar of FIATECH

ASKER

OK I'll try that. FYI recinji is the only define variable in the DB
Avatar of FIATECH

ASKER

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>
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
Avatar of FIATECH

ASKER

Yes I know. In the action page. I have my query insert and update on this page
did you do a cfdumpo to see what teh form contains?

<cfdump var=#form#">
does it show
recinj2
recinj
?
Avatar of FIATECH

ASKER

It says Variable RECINJ2 is undefined. in both pages!
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
Avatar of FIATECH

ASKER

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>

Avatar of FIATECH

ASKER

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
try this
<INPUT name="recinj2" type=checkbox Value="-888" onClick="setValue(this.name,'recinj')" <cfif not DK>checked</cfif>>Don't know</td>
Avatar of FIATECH

ASKER

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>>??
>>I don't think I can do this  <cfif not DK>checked</cfif>>??
no, try this instead

<cfif not trim(DK) EQ ''>checked</cfif>>??
Avatar of FIATECH

ASKER

No error this time but no saved check
ASKER CERTIFIED SOLUTION
Avatar of James Rodgers
James Rodgers
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FIATECH

ASKER

I changed it to and THAT SO WORKED!!!THANKS! I'm so happy!
glad i could help

thanks for the points