The "submit" button (SendYourMessage) works fine. The "Clear" button is working as though I clicked the "Submit" button and goes to the "Thankyou Page".
Although (somewhere in the back of my mind) I've seen "input type='image'", I've never used it. When most people speak of using images as buttons, they mean placing href tags around img tags, as in the following:
Insofar as your problem 1: I do not understand how it could be executing anything since you do not have any sort of event handler -- onClick or otherwise. Given that you are running ASP, I have to assume that you are using IE and that your submission is by the grace of Mr. Gates' programmers. (Has anyone checked the page out in Netscape?)
I would change the code to the following:
for the Submit image:
<a href='javascript:validateIt(this.form)'><img src="http://questiont.homestead.com/files/graphics/QT_But_SendYourMessage_Red.gif" WIDTH="100" HEIGHT="30" BORDER="0" ALT="Send Your Message"></a>
and for the Clear/Reset image:
<a href='javascript:this.form.reset()'><img.....></a>
The validateIt function would look something like:
function validateIt(formObj)
{
var ok2Send = true;
....code to test for empty fields, valid email address, etc. If the conditional's fail, set the ok2Send var to false.......
for (cnt=0; cnt<formObj.length; cnt++)
{
if (formObj.elements[cnt].type == 'text')
if(formObj.elements[cnt].value == '')
{
ok2Send = false;
alert("You must fill in something for " + formObj.elements[cnt].name);
formObj.elements[cnt].focus();
formObj.elements[cnt].select();
}
.....for each 'type'.....
}
if (ok2Send)
formObj.submit();
else
return false;
}
Re problem 2: try the same type of html as above: href, img, close href, and call a function to submit your form
If you want more explanation of the validateIt function, see the "Validating Forms" script/tutorial at my site.
Hope this helps
Vinny
[Edited by Vincent Puglia on 10-13-2000 at 10:45 PM]
Although (somewhere in the back of my mind) I've seen "input type='image'", I've never used it. When most people speak of using images as buttons, they mean placing href tags around img tags, as in the following:
I do not know where to place the additional script you referred to on the page or between what tags. Does it go on the form or the "HEAD" of the page? It is difficult for me to understand your tutorial since my knowledge of JavaScript is so limited right now.
I also have the same question about the changes you suggested for the Newsletter script.
I appreciate any additional help you can give me to get these scripts working properly.
Yea, you can call me by my first name, last name, 'Vinny', or any other nomenclature that most people would consider 'civil', including yo, dude, phreak, etc.
The validation script would go between the head tags. To make it easier for you:
change the href to: <a href="javascript:validateIt()".....>
change the form to <form name='somename' action='......
where somename is something you want to identify it by, like: myForm, msgForm, etc.
And the function to look like:
function validateIt()
{
var ok2Send = true;
if (document.formname.fieldname.value == '')
{
ok2Send = false;
alert('Please fill in the field.');
document.formname.fieldname.select();
document.formname.fieldname.focus();
}
if (ok2Send) document.formname.submit();
}
where formname is the name of the form, and fieldname is the name of the field that you require something entered, like for the email address field, it would look like:
if (document.msgForm.emailAdd.value == '')
{
ok2Send = false;
alert('Please fill in the field.');
document.msgForm.emailAdd.select();
document.msgForm.emailAdd.focus();
}
repeat the above for all fields that you don't want to be empty.
The final line would look like:
if (ok2Send) document.msgForm.submit();
Hope this helps
BTW: I knew I saw that used somewhere Did you go through the htmlgoodies javacript primer? That's actually where I first learned (and a book -- SAM's Javascript in 24 hours).
Bookmarks