this is strange: I have tried taking out the image and putting in a normal form submit button and I have added the code from Mike to say return true/false but when you ok the alert the form still submits itself.
I also tried the onSubmit code in the <cfform> tag but that didn't work at al (no alert box) so at the moment neither way is popping up an alert and leaving the form in place after pressing 'OK' to the alert ( you can try it at http://fclounge.cfdeveloper.co.uk/commentadd.cfm ) (on the comments big text box) _______________________________________________________ * Regards, Richard Lovelock Westminster City Council - Web Support Cap Gemini Ernst & Young Southbank 95 Wandsworth Road London SW8 2HG ( 0870 906 7482 _______________________________________________________ -----Original Message----- From: Paul Johnston [mailto:[EMAIL PROTECTED] Sent: 28 November 2003 12:04 To: [EMAIL PROTECTED] Subject: RE: [ cf-dev ] CFForm text box > 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] ======================================================= This message contains information that may be privileged or confidential and is the property of the Cap Gemini Ernst & Young Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorised to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ======================================================= -- ** 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]
