Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1175 How can I use an image as a "submit" button, yet still validate my form?

irt.org | Knowledge Base | JavaScript | Form 5 | Q1175 [ previous next ]

Q1175 How can I use an image as a "submit" button, yet still validate my form?

When you use JavaScript to submit a form then the onSubmit event handler is not triggered. Therefore you have to invoke the function, that the onsubmit event handler would have called, yourself:

<script language="JavaScript"><!--
function validate() {
    if ('black' != 'white')
        return false
    else
        return true;
}
//--></script>

<form onSubmit="return validate()">
<a href="javascript:;" onClick="if (validate()) document.myform.submit(); return false"><img src="my_button.gif"></a>
</form>

Feedback on 'Q1175 How can I use an image as a "submit" button, yet still validate my form?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.