Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q169 When using an image input type in a form how can I perform form validation on form submission?

You are here: irt.org | FAQ | JavaScript | Form | 5 | Q169 [ previous next ]

The input type image, is not officially part of specification of a form.

The following script attempts to overcome this problem. Rather than using an input type of image it uses a normal image link. The call to the check() function invokes the validate() function to perform the normal validation. The result then dictates whether the form is submitted using the submit() method.

<script language="JavaScript"><!--
function validate(myobject) {
    if (myobject.mytext.value == "yes")
        return true;
    else {
        alert('Data not completed successfully');
        return false;
    }
}

function check(myobject) {
    if (validate(myobject))
        myobject.submit();
}
//--></script>

<form name="myform" onSubmit="return validate(document.myform)">
<input type="text" name="mytext" value="">
<a href="javascript:check(document.myform)"><img src="animages.gif" border="0" width="16" height="16"></a>
</form>

Feedback on 'Q169 When using an image input type in a form how can I perform form validation on form submission?'

©2018 Martin Webb