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

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

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

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

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?'


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.