Click to See Complete Forum and Search --> : Trouble with java script and forms


Moonshadow
05-06-2003, 06:05 PM
Greetings all.
I'm brand new to the board and desperate.
I'm writing to you to request your assistance with a java script problem using javascript.
The situation is thus:
I've got an email form that I created awhile back on my website. I finally got the form to work correctly, but I wanted to make a further modification to it. I wanted to set it up so that certain fields were required. I went to http://javascript.internet.com/forms and found your script there, and have tried to install it on my page. The problem is that I can't get the script to work correctly. It won't let me NOT fill in the fields I designated as required. It still sends the information to my email instead of giving an error message saying that all fields need to be filled. I hope this is making sense.
I wonder if any of you could help me work the kinks out of this thing?
The page in question is:
http://www.desertmoonart.com/test.html

Thank you in advance for your time and attention in this matter.
--
You may also reply to me privately at this address:
info@desertmoonart.com

Charles
05-06-2003, 06:25 PM
Your script should look more like:

<script type='text/javascript'>
<!--

function verify(f) {

var theMessage = 'You are required to complete the following fields: ';
var status = true;

if (f.Name.value=='') {
themessage = themessage + ' - Name';
status = 'false';
};

if (f.Sex.value=='') {
theMessage += ' - Sex';
status = 'false';
}

if (f.Age.value=='') {
theMessage += ' - Age';
status = 'false';
};

if (f.Hair.value=='') {
theMessage += ' - Hair';
status = 'false';
};

if (f.Eyes.value=='') {
theMessage += ' - Eyes';
status = 'false';
};

if (f.Height.value=='') {
theMessage += ' - Height';
status = 'false';
};

if (f.Weight.value=='') {
theMessage += ' - Weight';
status = 'false';
};

if (f.Build.value=='') {
theMessage += ' - Build';
status = 'false';
};

if (f.Muscles.value=='') {
theMessage += ' - Muscles';
status = 'false';
};

if (f.Facial.value=='') {
theMessage += ' - Facial';
status = 'false';
};

if (f.Appearance.value=='') {
theMessage += ' - Appearance';
status = 'false';
};

if (f.Class.value=='') {
theMessage += ' - Class';
status = 'false';
};

if (f.Race.value=='') {
theMessage += ' - Racial';
status = 'false';
};

if (f.Clothing.value=='') {
theMessage += ' - Clothing';
status = 'false';
};

if (f.Weaponry.value=='') {
theMessage += ' - Weaponry';
status = 'false';
};

if (f.Medium.value=='') {
theMessage += ' - Medium';
status = 'false';
};

if (f.Size.value=='') {
theMessage += ' - Size';
status = 'false';
};

if (f.Laminate.value=='') {
theMessage += ' - Laminate';
status = 'false';
};

if (f.First.Name.value=='') {
theMessage += ' - First Name';
status = 'false';
};

if (f.Last.Name.value=='') {
theMessage += ' - Last Name';
status = 'false';
};

if (f.EMAIL.value=='') {
theMessage += ' - EMAIL';
status = 'false';
};

if (!status) alert(theMessage);
return status;
}

// -->
</script>

And your FORM tag should look like

<FORM ACTION="http://users.abac.com/cgi-bin/mail.pl" METHOD="POST" onclick="return verify(this)">

And you should remove the onclick handler from you submit button.

Moonshadow
05-06-2003, 07:09 PM
Thank you for your response..
I've made the changes you suggested, but it doesn't seem to have changed anything.

In the line that says:

And your FORM tag should look like

<FORM ACTION="http://users.abac.com/cgi-bin/mail.pl" METHOD="POST" onclick="return verify(this)">


Should I put something else in the place of "(this)"?

Charles
05-06-2003, 07:12 PM
No, 'this' needs to stay like that. Upload your new version so that I can see what's going on.

Moonshadow
05-06-2003, 07:15 PM
Consider it done, kind sir.

Charles
05-06-2003, 07:24 PM
Oops. I forgot to refresh the cache.

Line 32 contains an error of mine. It should read theMessage += ' - Name'; and not themessage = themessage + ' - Name';.

Line 1054 should read <select NAME="Medium"> and not <select NAME="medium">

Line 1074 should read <select NAME="Size"> and not <select NAME="size">

And so on. If you turn on the JavaScript error reporting on your browser you will quiclkly find the problems.