...

View Full Version : Ensuring Correct Field Entries but....



serendipity
02-26-2003, 06:11 AM
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?:confused:

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 :(

ShriekForth
02-26-2003, 04:38 PM
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.


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

serendipity
02-27-2003, 08:48 AM
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?

ShriekForth
02-27-2003, 03:08 PM
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

serendipity
03-02-2003, 08:28 PM
LOTSA THANKS!!! Both your advices worked! :)

serendipity
03-06-2003, 04:58 AM
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?

ShriekForth
03-06-2003, 04:19 PM
A set of functions I use often is ..


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

serendipity
03-07-2003, 02:27 PM
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!!!

serendipity
03-07-2003, 02:35 PM
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...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum