Nick Toye
05-25-2004, 05:38 AM
I have a form and I want to check if the data entered is a number if it isnt I want to be able to return an error message. I have the form pretty much nailed apart from this little problem.
// set some variables
//
//
mailform = "mailform.php";
confirm = "thanks";
error1 = "contact name required";
error2 = "company name required";
error3 = "number required";
error4 = "valid email required";
error5 = "input required";
error6 = "weight required";
codeError = "need code";
response.text = "";
//
//
//
//
// validate email function
//
function validate(address) {
if (address.length>=7) {
if (address.indexOf("@")>0) {
if ((address.indexOf("@")+2)<address.lastIndexOf(".")) {
if (address.lastIndexOf(".")<(address.length-2)) {
return (true);
}
}
}
}
return (false);
}
//
// clear form
function clearform() {
username.text = "";
company.text = "";
code.text = "";
telephone.text = "";
email.text = "";
from.text = "";
to.text = "";
weight.text = "";
nextDay_rb.setValue(true);
sameDay_rb.setValue(false);
before9_rb.setValue(false);
before12_rb.setValue(false);
response.text = "";
}
// form check
//
function formcheck() {
if ((((email.text == null)) || (email.text.length<1)) || (email.text == "valid email required")) {
email.text = error4;
formData.action = "";
}
if (!validate(email.text)) {
email.text = error4;
formData.action = "";
}
if ((username.text == null) || (username.text == "")) {
username.text = error1;
formData.action = "";
}
if ((company.text == null) || (company.text == "")) {
company.text = error2;
formData.action = "";
}
if ((code.text == "") || (!isNaN(code.text))) {
code.text = codeError;
formData.action = "";
}
if ((telephone.text == "") || (isNaN(telephone.text))) {
telephone.text = error3;
formData.action = "";
} if ((from.text == null) || (from.text == "")) {
from.text = error5;
formData.action = "";
}
if ((to.text == null) || (to.text == "")) {
to.text = error5;
formData.action = "";
}
if ((weight.text == null) || (isNaN(weight.text))) {
weight.text = error6;
formData.action = "";
}
if ((validate(email.text)) && (email.text != error4) && (username.text != "") && (username.text != error1) && (company.text != "") && (company.text != error2) && (code.text != "") && (code.text != codeError) && (telephone.text != "") && (telephone.text != error3) && (from != "") && (from.text != error5) && (to.text != "") && (to.text != error5) && (weight.text != "") && (weight.text != error6)) {
return (true);
}
}
//new LoadVars function
function sendInfo() {
trace("formcheck() returned true, run actions");
//test trace
formData = new LoadVars();
formData.username = username.text;
formData.company = company.text;
formData.code = code.text;
formData.number = number.text;
formData.email = email.text;
formData.from = from.text;
formData.to = to.text;
formData.weight = weight.text;
formData.delivery = deliveryGroup.getValue();
formData.action = "send";
// make new LoadVars for returned data
returnData = new LoadVars();
// send information
formData.sendAndLoad(mailform, returnData, "POST");
// load the returned data
returnData.onLoad = function(success) {
trace("----------------connected to php page----------------");
if (success) {
response.text = "thanks, a confirmation email has been sent to your email address";
} else {
trace("no returned data");
}
};
//------------test formData info, this will trace before returnData info
trace("formData.action ="+formData.action);
//test trace
trace("formData.name ="+formData.name);
//test trace
}
//end sendInfo()---------
stop();
I have highlighted the area that I need to change, many thanks in advance
Nick
// set some variables
//
//
mailform = "mailform.php";
confirm = "thanks";
error1 = "contact name required";
error2 = "company name required";
error3 = "number required";
error4 = "valid email required";
error5 = "input required";
error6 = "weight required";
codeError = "need code";
response.text = "";
//
//
//
//
// validate email function
//
function validate(address) {
if (address.length>=7) {
if (address.indexOf("@")>0) {
if ((address.indexOf("@")+2)<address.lastIndexOf(".")) {
if (address.lastIndexOf(".")<(address.length-2)) {
return (true);
}
}
}
}
return (false);
}
//
// clear form
function clearform() {
username.text = "";
company.text = "";
code.text = "";
telephone.text = "";
email.text = "";
from.text = "";
to.text = "";
weight.text = "";
nextDay_rb.setValue(true);
sameDay_rb.setValue(false);
before9_rb.setValue(false);
before12_rb.setValue(false);
response.text = "";
}
// form check
//
function formcheck() {
if ((((email.text == null)) || (email.text.length<1)) || (email.text == "valid email required")) {
email.text = error4;
formData.action = "";
}
if (!validate(email.text)) {
email.text = error4;
formData.action = "";
}
if ((username.text == null) || (username.text == "")) {
username.text = error1;
formData.action = "";
}
if ((company.text == null) || (company.text == "")) {
company.text = error2;
formData.action = "";
}
if ((code.text == "") || (!isNaN(code.text))) {
code.text = codeError;
formData.action = "";
}
if ((telephone.text == "") || (isNaN(telephone.text))) {
telephone.text = error3;
formData.action = "";
} if ((from.text == null) || (from.text == "")) {
from.text = error5;
formData.action = "";
}
if ((to.text == null) || (to.text == "")) {
to.text = error5;
formData.action = "";
}
if ((weight.text == null) || (isNaN(weight.text))) {
weight.text = error6;
formData.action = "";
}
if ((validate(email.text)) && (email.text != error4) && (username.text != "") && (username.text != error1) && (company.text != "") && (company.text != error2) && (code.text != "") && (code.text != codeError) && (telephone.text != "") && (telephone.text != error3) && (from != "") && (from.text != error5) && (to.text != "") && (to.text != error5) && (weight.text != "") && (weight.text != error6)) {
return (true);
}
}
//new LoadVars function
function sendInfo() {
trace("formcheck() returned true, run actions");
//test trace
formData = new LoadVars();
formData.username = username.text;
formData.company = company.text;
formData.code = code.text;
formData.number = number.text;
formData.email = email.text;
formData.from = from.text;
formData.to = to.text;
formData.weight = weight.text;
formData.delivery = deliveryGroup.getValue();
formData.action = "send";
// make new LoadVars for returned data
returnData = new LoadVars();
// send information
formData.sendAndLoad(mailform, returnData, "POST");
// load the returned data
returnData.onLoad = function(success) {
trace("----------------connected to php page----------------");
if (success) {
response.text = "thanks, a confirmation email has been sent to your email address";
} else {
trace("no returned data");
}
};
//------------test formData info, this will trace before returnData info
trace("formData.action ="+formData.action);
//test trace
trace("formData.name ="+formData.name);
//test trace
}
//end sendInfo()---------
stop();
I have highlighted the area that I need to change, many thanks in advance
Nick