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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I validate a textarea type field within a CFFORM? 3

Status
Not open for further replies.

ashw

MIS
Jun 10, 2002
61
CA
Hi I am new at this, so please help.
I have defined this:
<textarea name=&quot;weblinkdescription&quot;
rows=&quot;6&quot; cols=&quot;60&quot;></textarea>
within a <CFFORM></CFFORM> tag
How do I validate this textarea field so that an alert message should pop when the field is left blank, prompting, the user to enter the description.
Looking forward to yor help,
Regards ashw
 
yes.u will need to write a javascript above ur codes
urform is your form name
place tis script ard the head
<script language=&quot;javascript&quot;>
function check()(
if(document.urform.weblinkdescription.value.length==&quot;0&quot; || document.urform.weblinkdescription.value.charAt(0)==&quot; &quot;){
alert(&quot;Enter web link description!!&quot;)
document.urform.weblinkdescription.focus();
return false;}
}
</script>

finally at your submit button add this onClick=&quot;return check();&quot;

 
Dear Bondark,
Thanks so much for ur help. I wrote the following code in the head:

<script language=&quot;javascript&quot;>
function check()(
if(document.NewWebLink.weblinkdescription.value.length==&quot;&quot; ||
document.NewWebLink.weblinkdescription.value.charAt(0)==&quot;&quot;){
alert(&quot;Enter website description!&quot;)
document.NewWebLink.weblinkdescription.focus();
return false;}
}

and then above body
onsubmit=&quot;return check()&quot;>

but it shows the following error

ODBC Error Code = S1000 (General error)
[Microsoft][ODBC Microsoft Access Driver] Field 'tblweblink.weblinkDescription' cannot be a zero-length string.

The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (9:1) to (9:44).

Please help,
regards,
ashw
 
You have two options either open the database click on the field that is given in the error and set it to allow zero length strings, or you have to check that field and make sure it is not zero length. If you don't know how to check for that in the script let me know and I will write it out.

Wes
 
Yes that would work but depending on the type of data contained in this feild that could cause extra work. He would most likely have to check conditions to exclude the default value.
 
I got it done,I used obj.weblinkdescription instead of document
Thank you so much for your help,guys.
ashw
 
Thank you bondark. I used your example on my submit button of my cfform and it worked!! Thanks so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top