Click to See Complete Forum and Search --> : customer fill-out form help(!!!)


MASTERofPUPPETS
11-08-2003, 11:51 AM
hey, hey
what's up everyone?

i'm new to the world of javascript and i've encountered some problems while working on a customer fill-out form.

i'm hoping someone here could help me out... please...


here are my questions:

1. how do i connect a .js file (containing javaScript functions) to an html file that uses it's functions (a css file also needs to be connected to the same html files)?

2. how do i turn decimals from something like this, 2.23232423213, to something like this, 2.23?

3. i need to check that certain field within the customer form are filled in in a certain way... to me, the expressions i've used seem like they should work, but my computer disagrees. can anyone give me some suggestions on what i'm doing worng, or if i'm right on any of these?

Last Name --> STIPULATION: only letters

function checkLname(f)
{
var name= f.lname.value;
var expr= /^[A-Z a-z] ?/;
var pos= name.search(expr);

if(pos!=0)
{
alert("You must enter a valid Last Name");
f.lname.focus();
return false;

}else{
return true;
}
}


Frist Name --> STIPULATION: only letters

function checkFname(f)
{
var fname= f.fname.value;
var expr= /^[A-Z a-z] ?/;
var pos= fname.search(expr);

if(pos!=0)
{
alert("You must enter a valid First Name");
f.fname.focus();
return false;

}else{
return true;
}
}


Number, Streen Name --> STIPULATION: 123, Main Street

function checkStNo(f)
{
var address= f.address.value;
var expr= /^\d+, ?\[A-Z a-z]+ ?\[A-Z a-z]* ?/;
var pos= address.search(expr);

if(pos!=0)
{
alert("You must enter a valid Street Number and Street Name");
f.address.focus();
return false;

}else{
return true;
}
}


Telephone --> STIPULATION: (123)-456-7890

function checkPhone(f)
{
var phone= f.phone.value;
var expr= /^\1\d{3}\2-\d{3}-\d{4}$/
var pos= phone.search(expr);

if(pos!=0)
{
alert("You must enter a valid Phone Number");
f.phone.focus();
return false;

}else{
return true;
}
}


E-mail --> STIPULATION: ______@_______.com and/or ______@_______.ca

function checkEmail(f)
{
var email= f.email.value;
var expr= var expr= /^\w+\@\w+\.com$/;
var pos= email.search(expr);

if(pos!=0)
{
alert("You must enter a valid E-mail Address");
f.email.focus();
return false;

}else{
return true;
}
}


Credit Card --> STIPULATION: 5500000000000004 or 4111111111111111 only
???
any ideas?




thank you in advance.

96turnerri
11-08-2003, 12:15 PM
1)
<script language="javascript" src="JS/log.js"></script>
<a href="javascript:function()">Click Here</a>
2) http://javascriptsource.com look for rounding textboxes

zachzach
11-08-2003, 12:31 PM
answers for...
1.)

<script src="the path/thefile.js">dont put anything here</script>

===========================
2.)
lets pretent the variable A1=2.23232423213...

A1=2.23232423213
A2=A1.toString()
A3=A2.substring(0, 4)

so now if you did...

document.write(A3)

you would get...
2.23
===========================
3.)for first and last name:




function checkLname(f) {
var expr= "a"||"b"||"c"||"d"||"e"||"f"||"g"||"h"||"i"||"j"||"k"||"l"||"m"||"n"||"o"||"p"||"q"||"r"||"s"||"t"||"u"||"v"||"w"||"x"||"y"||"z"
var name= f.lname.value; //or f.fname.value;
var name2 = name.toLowerCase()
var pos= name2.indexOf(expr)

if(pos!=0) {
alert("You must enter a valid Last Name");
f.lname.focus(); //or f.fname.focus();
return false;
}else{
return true;
}
}

for address:

var expr2= "A"||"B"||"C"||"D"||E"||F"||G"||"H"||"I"||"J"||"K"||"L"||"M"||"N"||"O"||"P"||"Q"||"R"||"S"||"T"||"U"||"V"||"W||"X"||"Y"||"Z"||"a"||"b"||"c"||"d"||"e"||"f"||"g"||"h"||"i"||"j"||"k"||"l"||"m"||"n"||"o"||"p"||"q"||"r"||"s"||"t"||"u"||"v"||"w"||"x"||"y"||"z"||1||2||3||4||5||6||7||8||9||"1"||"2"||"3"||"4"||"5"||"6"||"7"||"8"||"9"||","

function checkLname(f) {
var name= f.address.value;
var name2=name.toString()
var name3=name2

var ma = 0

for(i=0;i<name3.length;i++) {
ss = name3.substring(i, i+1)
if(ss == expr2) {
var ma = ma+0
}
if(ss != expr2) {
var ma = ma+1
}
}


if(m!=0) {
alert("You must enter a valid Street number");
f.lname.focus();
return false;
}else{
return true;
}
}

for phone number:

var expr2= 1||2||3||4||5||6||7||8||9||"1"||"2"||"3"||"4"||"5"||"6"||"7"||"8"||"9"||"-"

function checkLname(f) {
var name= f.whatever.value;
var name2=name.toString()

var ma = 0

for(i=0;i<name2.length;i++) {
ss = name2.substring(i, i+1)
if(ss == expr2) {
var ma = ma+0
}
if(ss != expr2) {
var ma = ma+1
}
}


if(m!=0) {
alert("You must enter a valid Street number");
f.whatever.focus();
return false;
}else{
return true;
}
}


===========================
there you go that should work(make sure you fix the text boxes names in the script, sorry I forgot to do that 2 lazy!lol)
-zachzach

zachzach
11-08-2003, 12:34 PM
acually, for 96turnerri's link, use:
<a href="javascript:thefunctionname('a param', 'anotherparam')">Click here</a>

96turnerri
11-08-2003, 12:45 PM
hehee glad you used my method for some thought what you posted you were dismissing mine lol:D

zachzach
11-08-2003, 12:47 PM
lol, its just that "java script:" is not a valid system port(like a:/, c:/, vbscript:, aim:, ect), but "javascript:" is the correct way lol

MASTERofPUPPETS
11-08-2003, 01:21 PM
thanks to all who've contributed...

points 1) and 2) have been resolved, but point 3) i still have some questions about:

istead of using this kind of code var expr= "a"||"b"||"c"||"d"||"e"||"f"||"g"||"h"||"i"||"j"||"k"||"l"||"m"||"n"||"o"||"p"||"q"||"r"||"s"||"t"||"u"||"v"||"w"||"x"||"y"||"z" is there any way to check the text fields using Metacharacters and Metasymbols?

zachzach
11-08-2003, 02:56 PM
probably, but i dont know of them sorry.Ask pyro he probably knows some