Make sure the user does not enter or include the " " marks.

I have this validation that ask to user to enter "nda" if the data is not avalable.  But I want to get an alert to the user that if the "" marks are not required.

Can you please look at my code it is not working, coz i'm just starting to learn javascript

Thanks in advance

if (Form.Authority.value == "") || (Form.Authority.lenght > 3){
     alert("Please fill in  Authority information. \nIf data is not available, please
     type "nda" without the "" marks.");
     Form.Authority.focus();
     return false;
}

Thanks
mdbboundAsked:
Who is Participating?
 
sigmaconCommented:
mdbbound, you are asking javascript questions! the javascript forum may be more appropriate. here's my answer anyway. Note: be careful with your parentheses:

if (Form.Authority.value == "" || Form.Authority.lenght > 3 || Form.Authority.indexOf('"') > -1){
     alert("Please fill in  Authority information. \nIf data is not available, please
     type "nda" without the "" marks.");
     Form.Authority.focus();
     return false;
}
0
 
mrichmonCommented:
You can handle in CF.

Don't bother the user with the fact that they have to leave out the " "
Instead just use Replace function to remove " if they add it.

That way the user doesn't get an error and neither does your system.
0
 
mdbboundAuthor Commented:
Hi

Can someone please move this Q to javascript.  Thanks
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
mdbboundAuthor Commented:
Mrichmon,

Thanks for your suggestion, I think that is even better just in case the javascript is turned off. I just don't know the replace function yet.  If you think this Q should go to the javascript, please move it.

Thanks
0
 
Tacobell777Commented:
I would not allow them to type in anything, if empty then you assume NDA, or put a checkbox next to the textfield, when ticked then consider it as NDA... What if they type in NAD or DNA ? The checks are endless, just use a checkbox, or leave empty.

Or use regular expressions to filter your data..
0
 
mrichmonCommented:
No since I would do the Replace server side after it is submitted.....

Here is help:

http://livedocs.macromedia.com/coldfusion/6/CFML_Reference/functions-pt266.htm
0
 
sigmaconCommented:
A) mdbbound, I answered your the specifc question, just wanted to let you know that you were asking JS-related questions!
B) mrichmon is, as usual ;-), right. Form validation should be performed on the server side NO MATTER WHAT
C) JavaScript can help improve the user experience, so it's ok to use it if you're getting paid for it
0
 
Tacobell777Commented:
I seriously think that putting one check in place for " is not good enough, just think of how many other things could be entered wrong....
0
 
mrichmonCommented:
I think that all three of the following are good suggestions/points:

1) from sigmacon - a way to test in javascript...
2) from myself - a way to strip out the " in CF...
3) from Tacobell - use regular expressions or some other additional checks to catch any other situations you don't want....
0
 
mdbboundAuthor Commented:
Well,

I actually want javascript and CF server-side.  The problem is i don't know how to do it.  I will try all the suggestions.

Thanks, i will get back as soon as i can.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.