I’m trying to do a modify a form, but I don’t know javascript very well and have cobbled this together.
It is to verify entry into a php form. The form will work fine with if I use the regular onsubmit form function with the checkaddr function. I don’t know how to put a bunch of them together and have copied and pasted from a bunch of other pages to make it look the same. But it wont work. Could any javascript experts take a look at my code and tell me how to make it all work.
script type=”text/javascript”>
function formValidator(){
var FirstName = document.getElementById(’FirstName’);
var Email = document.getElementById(’Email’);
var EmailVerify = document.getElementById(’EmailVerify’);
var Message = document.getElementById(’Message’);
if(isAlphabet(firstname)){
if(chkaddr(Email,EmailVerify)){
if(lengthRestriction(Message,0,256)){
return true;
}
}
}
return false;
}
function isAlphabet(elem){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(’Please enter only letters for your name.’);
elem.focus();
return false;
}
}
function chkaddr(first, second) {
var el, msg = ‘’;
if (first.value == ‘’ || /^\s+$/.test(first.value)) {
msg = ‘Please enter your email address.’;
el = first;
}
else if (second.value == ‘’ || /^\s+$/.test(second.value)) {
msg = ‘Please re-enter email address.’;
el = second;
}
else if (second.value != first.value) {
msg = ‘Please ensure that your email address & confirmed email address are the same.’;
el = second;
}
if (msg) {
alert(msg);
el.focus();
el.select();
return false;
}
return true;
}
function lengthRestriction(elem, min, max) {
var uInput = elem.value;
if(uInput.length >= min && uInput.length = max){
return true;
}
else{
alert(’Please enter fewer than 256 characters.’);
elem.focus();
return false;
}
}
/script>
This open post was written 3 months, 2 weeks ago | V/U/S: 69, 1, 2 | Edit Post | Leave a reply | Report Post
Reciprocity (0)
Since writing this post billyocracy may have helped people, but has not within the last 4 days. billyocracy is a verified member, has been around for 4 months, 3 weeks and has 8 posts and 0 replies to their name.
Invite Others to Help
A logged in and verified Help.com member has the ability to setup a Friends List and invite others to help with posts.
