• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 128
  • Last Modified:

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
0
mdbbound
Asked:
mdbbound
  • 3
  • 3
  • 2
  • +1
4 Solutions
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now