Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
89
rated 0 times [  90] [ 1]  / answers: 1 / hits: 42026  / 12 Years ago, fri, june 1, 2012, 12:00:00

I have a form for a registration page. The form contains an image that changes its src dependant on a situation.
Within a script which activates upon submission of the form, I want the form to call an alert if that image has a particular src, so I need a way of retrieving and comparing 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 &raquo;/>

More From » html

 Answers
17

Use this:



if (document.getElementById('FName_Status').getAttribute('src') == pictures/apic.png)

[#85224] Thursday, May 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryderalfonsos

Total Points: 655
Total Questions: 88
Total Answers: 91

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
ryderalfonsos questions
Mon, Sep 9, 19, 00:00, 5 Years ago
Wed, Feb 13, 19, 00:00, 5 Years ago
Tue, Feb 12, 19, 00:00, 5 Years ago
Fri, Dec 28, 18, 00:00, 6 Years ago
;