Jump to content

input type="image" with a little javaScript


Elemental

Recommended Posts

Hey Folks, Hope all are doing well ...I have the following on a document:

<html><head><script type="text/javascript">function mouseOver(){document.b1.src ="dbblImage.png";}function mouseOut(){document.b1.src ="snglImage.png";}</script></head><body><img src="snglImage.png" name="b1" id="submitBtn" onmouseover="mouseOver()" onmouseout="mouseOut()" alt="Submit Button" title="Submit Button" /></body></html>

This works fine, as is, but when I try using the same script with a form's <input type="image"> I get an error: Object doesn't support this property or method.Here's the code I'm using with the <input> tag:

<html><head><script type="text/javascript">function mouseOver(){document.myForm.getElementById("submitBtn").src ="dbblImage.png";}function mouseOut(){document.myForm.getElementById("submitBtn").src ="snglImage.png";}</script></head><body><form name="myForm"><input type="image" src="snglImage.png" name="b1" id="submitBtn" onmouseover="mouseOver()" onmouseout="mouseOut()" alt="Submit Button" title="Submit Button" /></form></body></html>

It looks like the <input> tag doesn't like the "onmouse" events or I'm just writing it wrong or both.Can one of you beautiful people help me understand what I'm doing wrong here?Any help would be appreciatedPeace,Elemental

Link to comment
Share on other sites

Why document.myform.getElementById...? Try just:

function mouseOver() {	document.getElementById("submitBtn").src ="dbblImage.png";}function mouseOut() {	document.getElementById("submitBtn").src ="snglImage.png";}

Link to comment
Share on other sites

Why document.myform.getElementById...? Try just:
function mouseOver() {	document.getElementById("submitBtn").src ="dbblImage.png";}function mouseOut() {	document.getElementById("submitBtn").src ="snglImage.png";}

Synook, Awesome, thank you that worked like a charm.As the why "document.myForm.getElementById()" when I originally added the "myForm" the error "Object doesn't support this property or method" stopped so I thought I was moving in the right direction; it didn't occur to me to remove it and just use the "document.getElementById()".Thank you for the education, it's much appreciated.Peace,Elemental
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...