cfinput tag problem

Hi!  I need to insert a loop, textfields and checkboxs, into database.  After I submit the form, I get this error message:

Attribute validation error for tag CFINPUT.
The value of the attribute TYPE, which is currently "text1", must be one of the values: RADIO,CHECKBOX,PASSWORD,TEXT.
The Error Occurred in C:\CFusionMX\wwwroot\CS1530 Project\create_exam.cfm: line 109

107 :   <!--- use a counter as shown below, the counter becomes part of the variable name
108 :   so you will have text1, text2, etc... --->
109 :   <td><cfinput type="text#counter#" name="ans_answer" value="" size=120></td>

Notice: I only get error about type="text#counter#", but not an error for type="checkbox#counter#."  Please let me know what cause this error.
<cfloop index=counter from="1" to="10" step="1">
  <!--- use a counter as shown below, the counter becomes part of the variable name
  so you will have text1, text2, etc... --->
  <td><cfinput type="text#counter#" name="ans_answer" value="" size=120></td>
  <td><cfinput type="checkbox#counter#" name="correct" value=""><br></td>
<!--- <td><input type="checkbox" name="correct" value="No"><br></td>--->
<cfset q_ans_id=counter>

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

James RodgersWeb Applications DeveloperCommented:
<td><cfinput type="text#counter#" name="ans_answer" value="" size=120></td>

<td><cfinput type="text" name="ans_answer#counter#" value="" size=120></td>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James RodgersWeb Applications DeveloperCommented:
if you are looking for a yes/no answer you should use radio buttons instead of checkboxes, you can select both options in a checkbox situation but you can only check one radio button option in a group

<td><cfinput type="radio" name="radAnswer#counter#" value="yes"></td>
<td><cfinput type="radio" name="radAnswer#counter#" value="no"></td>
yes jesters right

the type should be text,radio,checkbox etc...
u can't change that. u always change the name attribute..

Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

You are trying to dynamically change the type of the inputs.  This is incorrect.  I think what you want to do is dynamically create the names of the inputs.

The reason that you only get an error for the text type is because it stops processing the page after the first error.  If you fix that one then it will again die on the second error.

So when you  dynamically create inputs you should do it like this :

<input type="checkbox" name="checkbox#counter#">
or like this :
<input type="text" name="text#counter#">

THese of course need to be within a cfoutput so that the #counter# will be evaluated.

Then on the procesing page you can access them like this :

<cfset currenttext = Form["text" & counter]>
<cfset currenttext = Evaluate("Form.text#counter#")>
yrs7Author Commented:
Thanks for all experts help!  I have one question for mrichmon.... do I need to put <cfset currenttext = Form["text" & counter]> in a loop to insert the 10 textfields and checkboxes into database?
no just use Evaluate("Form.text#counter#"), it will work fine.

but for radio buttons and checkboxes u will have to see wether its defined or not

<cfif isdefined("form.text#counter#")>

Yes you need to put it in a loop that increments the counter or you can manually increment the counter

Like this :

<cfloop index="counter" from="1" to = "#numfields#>
<cfset currenttext = Form["text" & counter]>

And you can do whatever else you want in the loop.

The Evaluate("Form.text#counter#") does the same thing - it is just an older syntax and personally I like the newer syntax better because it is cleaner to write - and actually works in some situations where the Evaluate syntax doesn't (as your dynamically generated pages get more complex - for example allowing the user to dynamically add and remove rows from your forms)
yrs7Author Commented:
Hello!  I got a problem in a part which is executed before the code posted above.  I will get back to you after I fix that part of problem.  
Best Regard
mrichmon : "and actually works in some situations where the Evaluate syntax doesn't ????"

buddy i have been using this for very long time and with many complicated loops and variables, but i have never come across any hassleswith evaluate...

Well, I too felt the same way - I had been usin gthe evaluate syntax only and it always seemed to work... and then boom - I write an even more complex program and now it no longer works.  It would be too off topic to post the entire thing here - but if Evaluate works for all of your situations then you can stick with that.  Me? - I and the other programmers that I correspond with on other forums have all decided to move to the other syntax as we have come accross these situations.

At least keep the alternate syntax in mind in case you do ever come accross one of these cases...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.