Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine the type of Input?

Status
Not open for further replies.

lizok

Programmer
Jan 11, 2001
82
US
Hello, i was wondering is there a way to determine the type of input used on the form?

i have a bunch of dynamic fields that i create on the fly: some are checkboxes, some are radio buttons, etc.

in Javascript id would be document.form.element.type

How would i do that in CF? (on Submit i am trying to determine the type of the input and then process the value of that input field)

thank you
 
The only info passed to the form action page is name/value pairs. You'd have to roll your own identifier collection or create metadata tags, i.e., for each element, have a correlating hidden form field that holds the element type, like

<input type="hidden" name="Myfield_type" value="checkbox">


<input type="checkbox" name="Myfield">

HTH,



Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'll have the roast duck with the mango salsa.
 
Thank you for response. Maybe i am complicating things. i generate CF page on the fly. Some fields are checkboxes, some radio buttons. i was thinking about how will i know how to process data from those fields on the action page? if the dynamic input field is checkbox, i was thinking to check what type it was. if it's a checkbox then i'd use isdefined() and then update DB with value from that checkbox. and so on....maybe there is an easier way to do that
 
Name all of your form elements so that you can later determine what they are.
Code:
<input type="checkbox" name="cb_MyCheckBoxfield">
<input type="radio" name="rb_MyRadioButtonfield">

---[i]action page[/i]---

<cfloop list="#form.fieldnames#" index="f">
  <cfif ListFirst(Form["#f#"],"_") EQ "cb">
      This is a Check Box:  #FORM[f]# - #f#
  <cfelseif ListFirst(Form["#f#"],"_") EQ "rb">
      This is a Radio Button:  #FORM[f]# - #f#
  </cfif>
</cfloop>

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
thank you so much...i felt there was an easier way out :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top