Hi there
I’m trying to make a specific field required on a contact form but the current js is coded to allow for more than one field to be used and it will send. I need to make the contact number field required so that users are prompted to add it if the field is omitted for any reason.
Here’s the current code snippet:
app.contactSend = function(e) {
if ( typeof e != “undefined” )
e.preventDefault();
var doc = document,
fullName = doc.getElementById(“fullName”),
email = doc.getElementById(“emailAddress”),
contactNumber = doc.getElementById(“contactNumber”),
company = doc.getElementById(“company”),
message = doc.getElementById(“message”);
if ( fullName.value == “” && ( email.value == “” || contactNumber.value == “” ) && message.value == “” ) {
if ( fullName.value == “” )
app.fieldToFocus = fullName;
else if ( email.value == “” && contactNumber.value == “” )
app.fieldToFocus = contactNumber;
else
app.fieldToFocus = message;
alert(“Please complete your name, either a contact number or email address and a message.”, “Contact Us”, function(){ app.fieldToFocus.focus() });
return;
}
app.post(“../controller/webService.php?fullName=” + fullName.value + “&emailAddress=” + email.value + “&contactNumber=” + contactNumber.value + “&company=” + company.value + “&message=” + message.value ,
function(d) {
if ( d == “0” )
alert(“Your enquiry has been successfully sent.”, “Contact Us”);
else
alert(“Your enquiry could not be sent. Please try again later.”, “Contact Us”);
},
function() {
alert(“Your enquiry could not be sent. Please try again later.”, “Contact Us”);
}
);
}
Any help is appreciated and thanks in advance