I have a form for the registration page. The form contains an image that changes its src depending on the situation. Inside the script that activates when the form is submitted, I want the form to raise a warning if this image has a specific src, so I need a way to get and compare the value.
HTML:
<form action="register_submit.php" method="post" name="mainform" enctype="multipart/form-data" onSubmit="return checkForm(this);return false;">
JS:
function checkForm(f) {if ([image src value] == "pictures/apic.png") { alert("error picture is apic"); return false; } else { f.submit(); return false; } }
Here is the relative code in full:
<script type="text/javascript"> function checkForm(f) {if ([image src value] == "pictures/apic.png") { alert("error picture is apic"); return false; } else { f.submit(); return false; } } </script> <form action="register_submit.php" method="post" name="mainform" enctype="multipart/form-data" onSubmit="return checkForm(this);return false;"> <div class="required"> <label for="first_name">*First Name:</label> <input type="text" name="first_name" id="first_name" class="inputText" onkeyup="checkFName(this.value);" onblur="checkFName(this.value);" maxlength="20" size="10" value="" /> <img id="FName_Status" name="FName_Status" src="/pictures/bad.png" style="margin-left:5px; position:absolute;" alt="FName_Status" /> </div> (OTHER OBJECTS) </form> <input type="submit" name="sub" class="inputSubmit" value="Submit »"/>
source share