kellyw
01-02-2007, 09:54 PM
Hello.
I have created a simple php form on <a href="http://iguanacreek.com/contactform.htm">this</a> page and have added a javascript validator to check for a name and email address. The validator works and the php page is correctly called up, however the email comes back with blank fields. I have double checked all field names and all are correctly referenced.
The problem lies somewhere in the validator javascript code.
function isMailAddress(m) {
if ((m == '') || (m == ' ')) { return false; }
var a = 1;
var ml = m.length;
while ((ml>a) && (m.charAt(a) != "@")) { a++ }
if ((a >= ml) || (m.charAt(a) != "@")) {
return false;
} else {
a = a + 2;
}
while ((ml > a) && (m.charAt(a) != ".")) { a++ }
if ((a >= ml - 1) || (m.charAt(a) != ".")) {
return false;
} else {
return true;
}
}
// For Contact Form
function validate(obj) {
var valid = true;
var msg = "";
if (obj.elements["name"].value == "") {
msg += "Please enter your name.\n";
valid = false;
obj.elements["name"].focus();
}
if (!isMailAddress(obj.elements["email"].value)) {
msg += "Please enter a valid email address.\n";
if (valid) {
valid = false;
obj.elements["email"].focus();
}
}
if (!valid) alert(msg);
return valid;
}
The Firefox javascript console gives me the following error:
[Exception... "'Permission denied to set property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: http://iguanacreek.com/validator.js :: validate :: line 40" data: no]
[Break on this error] if (!valid) alert(msg);
Does anyone know what this means? I've used the same base php form code and js validator code on many other web sites without any problems.
Thanks in advance.
Kelly W
I have created a simple php form on <a href="http://iguanacreek.com/contactform.htm">this</a> page and have added a javascript validator to check for a name and email address. The validator works and the php page is correctly called up, however the email comes back with blank fields. I have double checked all field names and all are correctly referenced.
The problem lies somewhere in the validator javascript code.
function isMailAddress(m) {
if ((m == '') || (m == ' ')) { return false; }
var a = 1;
var ml = m.length;
while ((ml>a) && (m.charAt(a) != "@")) { a++ }
if ((a >= ml) || (m.charAt(a) != "@")) {
return false;
} else {
a = a + 2;
}
while ((ml > a) && (m.charAt(a) != ".")) { a++ }
if ((a >= ml - 1) || (m.charAt(a) != ".")) {
return false;
} else {
return true;
}
}
// For Contact Form
function validate(obj) {
var valid = true;
var msg = "";
if (obj.elements["name"].value == "") {
msg += "Please enter your name.\n";
valid = false;
obj.elements["name"].focus();
}
if (!isMailAddress(obj.elements["email"].value)) {
msg += "Please enter a valid email address.\n";
if (valid) {
valid = false;
obj.elements["email"].focus();
}
}
if (!valid) alert(msg);
return valid;
}
The Firefox javascript console gives me the following error:
[Exception... "'Permission denied to set property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: http://iguanacreek.com/validator.js :: validate :: line 40" data: no]
[Break on this error] if (!valid) alert(msg);
Does anyone know what this means? I've used the same base php form code and js validator code on many other web sites without any problems.
Thanks in advance.
Kelly W