work help: I’m trying to do a modify a form, but I don’t know javascript very well and have cobbled this together. - Help.com

billyocracy
offline Verified (4 months, 3 weeks) Visit billyocracy's shoutbox
An Unknown Location

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) Reciprocation Failure -- The poster has NOT helped anyone else yet!

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.

Post Tags (10)

Replies (1)

Where were you?

Click and drag to move the map around. FAQ: How we place people on this map »
You can also watch events on Help.com as they happen
Mouse over the map for 2 seconds to see an expanded, interactive view

anonymous43242342342 offline Unverified User #
An Unknown Location | 3 months, 2 weeks ago (3 minutes after post)

This isn’t the best forum for that question. Not many coders come here. There is a short tutorial on http://www.w3schools.com/ that would help you quickly understand things properly. After that you may be able to sort your problem out yourself.

Quote this reply Report this reply to moderators
This account has been deactivated.

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.