Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ensuring Correct Field Entries but....

    Hello again,

    I've been trying to really put together this script to be more...uhmm..."form friendly" to site visitors or whoever would care to fill it up...but at the same time, make sure that they properly fill up the field forms...i.e. really put in a correct email, telephone nos. etc...

    The script attached has already been "fixed" of some bugs (at least those w/c ive found)...thanks to a couple of forumers here and there..( i think...see my previous posts). However, I still want it to be even more... "form friendlier"...if you care to check out the script...all fields ensure that all the data field entries are correctly inputted..name, email, telephone no. etc...however, it also Requires that these fields are filled up before submit (you can't leave it blank)...How can I turn this "requirement" off without sacrificing that the correct field entries are inputted??? What do I need to take out or edit from the script?

    I just realized that I seem to have focused too much in requiring that field entries Not only be properly filled up but also have to be filled up..it's become to restrictive
    Attached Files Attached Files
    Thanks in advance for any replies! :)

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Western US
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Probably the simplest way would be to check if the field that is optional contains any value to start with. If it does contain a value, then you can run your validation against it. If it is empty, don't validate so you don't return a format error. For example in the case of he phone number it would be something like this.
    Code:
    function isReady(form) {
    ...
        if (form.requiredtelephone.value != ''){
         if (isNumber(form.requiredtelephone.value) == false) {
            alert("Please enter a valid telephone no.");
            form.requiredtelephone.focus();
            return false;
        }
       }
    ...
    }
    ShriekForth

  • #3
    New Coder
    Join Date
    Feb 2003
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, i seem to see what u mean...but even before I applied the change you suggest...I realized that there's a script error I had overlooked...

    I get this:

    Line: 73
    Char: 9
    Error: 'return' statement outside of function
    Code: 0

    Uhmm, what does this mean? and how do I fix this first?
    Thanks in advance for any replies! :)

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Western US
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    On line 69, you start a function, isProper that function is closed on line 71 , and then

    return true;
    else
    return false;
    }

    is just sitting by itself, not in a function therefore the 'return' statement outside of function Just delete those 4 lines.

    ShriekForth

  • #5
    New Coder
    Join Date
    Feb 2003
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    LOTSA THANKS!!! Both your advices worked!
    Thanks in advance for any replies! :)

  • #6
    New Coder
    Join Date
    Feb 2003
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello again,

    I'm not sure if this thread is still being read or followed but I might as well repost it here also....

    Previously, I had a "problem" with the Name field not accepting any data entries with more than 2 blank spaces in between entries ex. Richard E. Small (space between Richard and the E and the Small) returned an invalid name prompt....

    Now, how can I make another "Numbers only field" that Should NOT accept any blank spaces in between??

    What should be added into the script?
    Thanks in advance for any replies! :)

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    Western US
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A set of functions I use often is ..
    Code:
    function isNumeric(string){
    	for (x=0;x<string.length;x++){
    		if (!isDigit(string.charAt(x)))	{
    			return false;
    			}
    		}
    	return true;
    }
    
    function isDigit(dig){
    	return((dig<="9")&&(dig>="0"));
    }
    isNumeric iterates a character at a time though the input string, and passes it to isDigit which checks to see if it is between 0 and 9. If it's not a false gets returned all the way back triggering the error. Works just like the others you have here.

    Add these to your script, and for the field you want to validate numeric values only do something like this (example field name)


    if (isNumeric(form.requiredNumericField.value) == false) {
    alert("Please enter a valid Number, no spaces or special characters.");
    form.requiredNumericField.focus();
    return false;
    }

    ShriekForth

  • #8
    New Coder
    Join Date
    Feb 2003
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Shrieking...with Delight :)

    Gee...Thanks!!! It was so easy to add on to the script...but i took out this piece of code somewhere at the end of the script: coz it was making a return statement error and object expected error prompt
    ___________
    return true;
    }
    ____________

    w/c makes me kinda uneasy coz i might be missing something here...so you might want to check it out...


    Also, and this is the last, last one I need to figure out in the script...in the isNumeric function...(i should really have asked this before)...how can I ensure that if a site visitor enters data into this field ex. Cellular Phone IMSI, they would ONLY be able to enter numeric digits (no problems here), without any spaces in between (this one is also ok..) but if they do enter digits..it should be 16digits nothing more (this one has been solved by max length)...and not less than 16 digits...(min.length??)...or will this mess up the script??

    Again...Thanks a lot!!!
    Attached Files Attached Files
    Thanks in advance for any replies! :)

  • #9
    New Coder
    Join Date
    Feb 2003
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Uhmm...nope putting in a "min. length"...does nothing to make the script fix the "should-be=16digits only" or must be left blank

    Is there something I should insert further into the script to make this work?

    Please...
    Thanks in advance for any replies! :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •