> Paul - thanks for that code....almost works but not quite. I
> get the alert box and message as requested BUT when I OK the
> alert message the form still submits itself???
>
> CODE IS:
> <script language="Javascript">
> function checkForm(myform) {
> if(myform.comments.value.match(/^\s*$/)) {
> // it's empty
> alert('You must enter a value for comments');
> }
> else {
> myform.submit();
> }
> }
> </script>
>
> <textarea name="comments" cols="50" rows="12"></textarea>
>
> <input type="image" src="images/submit.gif"
> onClick="checkForm(this.form);">
>
> Is it because I am using an image for button???
Simple answer is yes (unfortunately).
Basically, the type="image" is the same as type="submit" but just using an
image.
The way round this is to change it into a normal img tag inside an anchor
tag:
<a href="javascript:checkForm(document.formName);"><img
src="images/submit.gif" /></a>
The problem then comes with cross-browser compatibility. You have to ensure
that the form is referenced correctly for all browsers.
The other way around this, is to put the onSubmit="return checkForm(this);"
into the <CFFORM> tag (I am unsure as to whether this will work at all!).
Then instead of the above code, do this:
Ie <CFFORM> would return this type of <form> tag:
<form action="blah.cfm" method="post" onSubmit="return checkForm(this);">
<script language="Javascript">
function checkForm(myform) {
if(myform.comments.value.match(/^\s*$/)) {
// it's empty
alert('You must enter a value for comments');
return false;
}
else {
return true;
}
}
</script>
HTH
Paul
--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]