|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Inserting a Check box value
The undermentioned is how my cfm file looks.when i dont check any of the checkboxes, I get a error message "Variable Q4 is undefined", but I do not get it if i leave "q9" blank, which is a textarea. I hope all of this text would'nt be smushed and incomprehensible. Please help.
<CFQUERY name="survey101" datasource="survey"> INSERT INTO SURVEY_101(OTHER, <CFIF q4 Is Not ""> STAYED, </CFIF> <CFIF q9 Is Not ""> COMMENTS, </CFIF> ) Values('#q10#', <CFIF q4 Is Not ""> '#q4#', </CFIF> <CFIF q9 Is Not ""> '#q9#', </CFIF> ) </CFQUERY> <html> <form name="survey101" action="http://www.dadadxcj.com/Survey101/survey_vj.cfm" method="post"> <label for="10.36">Other</label><br> <input id="10.36" size="60" name="q10"><br> <p>4. Having stayed at this property, did you (select all that apply):*</p> <input type="checkbox" value="12" name="q4"><label for="4.12">Receive the applicable rate?</label><br> <input type="checkbox" value="13" name="q4"><label for="4.13">Have to pay actual expenses rate?</label><br> <p>5. What would you change (add or substract) about the website?</p> <textarea id="9.35" name="q9" rows="5" cols="40"></textarea><br> <input type="submit" value="Submit" name="submit"> </form> </html> |
|
#2
|
|||
|
|||
|
A couple of things. First, when in doubt, dump it. Use cfdump to output the form scope and see what is there. HTML form checkboxes are not sent if they are not checked. So if the user doesn't check the check box, there will be no form variable for that field. I would use cfparam to set a default value of false if the variable isn't present in the form scope.
And speaking of form scope, if your query is using variables in the form scope, then prefix them with "form." Always scope anything not in the local variables scope for clarity and performance. If you don't scope, CF has to go look up the chain of scopes to try and find a match. This hurts performance but more importantly, if you have the same variable in multiple scopes it is easy to end up with the wrong one! Hope all this helps.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
Thank You..that was so simple and it worked.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Inserting a Check box value |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|