Solved

cfinput tag problem

Posted on 2003-11-18
13
497 Views
Last Modified: 2013-12-24
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">
<tr>
  <td>#counter#.</td>
  <!--- 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>--->
</tr>
<cfset q_ans_id=counter>
</cfloop>

0
Comment
Question by:yrs7
  • 3
  • 3
  • 2
  • +1
13 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 25 total points
ID: 9775164
change
<td><cfinput type="text#counter#" name="ans_answer" value="" size=120></td>

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

Expert Comment

by:James Rodgers
ID: 9775191
also
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>
0
 
LVL 11

Expert Comment

by:hart
ID: 9776430
yes jesters right

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

Regards
Hart
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 9781016
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]>
or
<cfset currenttext = Evaluate("Form.text#counter#")>
0
 

Author Comment

by:yrs7
ID: 9786067
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?
Sicnerely
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 11

Expert Comment

by:hart
ID: 9786110
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

i.e
<cfif isdefined("form.text#counter#")>
#Evaluate("Form.text#counter#")#
</cfif>

Regards
Hart
0
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 25 total points
ID: 9788547
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]>
</cfloop>

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)
0
 

Author Comment

by:yrs7
ID: 9790614
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
Ying
0
 
LVL 11

Expert Comment

by:hart
ID: 9794728
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...

Regards
Hart
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 9811756
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...
0

Featured Post

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Join & Write a Comment

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now