Link to home
Start Free TrialLog in
Avatar of jturkington
jturkington

asked on

Dynamic Max Length Setup

I have 15 odd form fields that i need to setup their maxlengths that are taken from a SQL table but i am having problems trying to figure out how to associate each database max length value with each form field !?


For Example...

Table
jobboardid   fieldidfk            maxlength
   1                  1                     100
   2                  1                      75
   3                  2                      75
   4                  2                      50

select fieldfk,min(maxlength)
from table
group by fieldfk

Output
fieldfk       min(maxlength)
1                 75
2                 50

Form Field

<input name="name" value="#FORM.name#" type="text" maxlength=" ??????????" />

What would be the best way to set this up for the 15 form fields, maybe using cfif's compares ??

Cheers

JT
Avatar of trailblazzyr55
trailblazzyr55

Hello,

SELECT MAX(field1) AS FieldCountOne, MAX(field2) AS FieldCountTwo, MAX(field3) AS FieldCountThree
FROM YourTable

<input name="name" value="#FORM.name#" type="text" maxlength="#FieldCountOne#"/>....



>>What would be the best way to set this up for the 15 form fields, maybe using cfif's compares ??  not sure what yo mean....
I would prefer <cfscript> less clutter, faster?
SOLUTION
Avatar of pinaldave
pinaldave
Flag of India 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


This may be better to use..

SELECT COUNT(field1) AS FieldCountOne, COUNT(field2) AS FieldCountTwo, COUNT(field3) AS FieldCountThree
FROM YourTable
Avatar of jturkington

ASKER

trailblazzyr55 i dont have individual columns for each form field they are all in the column fieldidfk
errrr. read the question wrong ;^)

pinaldave's should work :o)
pinaldave i have a three of four textarea fields how do i get around this ?!?
Hi jturkington,
I did not understand what does it mean by three of four textarea

Regards,
---Pinal
Hi jturkington,
if you mean to say that there three textarea the maxlength will not work. you need some javascript validation for that. or serverside validation(which only works with submit)

Regards,
---Pinal
ahh i see pinaldave, looks like i have to manually enter the max lengths as and when they change for each form field !
ASKER CERTIFIED SOLUTION
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
Is there no way to setup 15 variables at the start of the form
eg

Field1maxlength = query.maxlength1
Field2maxlength = query.maxlength2
etc..

and use the variables on the form to set max length and server side validation ??
SOLUTION
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