Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mouseover swap image in INPUT? 1

Status
Not open for further replies.

forecasting

Programmer
May 2, 2002
130
I want to submit a form using an image for my submit button that changes when the user does a mouseover. When I mouseover with this code I get the error "document[...] is null or not an object." Can anyone help?

<form method=&quot;post&quot; action=&quot;logic.asp&quot;>
<INPUT type=&quot;text&quot; name=uname>
<INPUT type=&quot;password&quot; name=pwd>
<INPUT type=&quot;image&quot; name=&quot;img1&quot; SRC=&quot;submit.gif&quot; onMouseOver=&quot;imgOn('img1')&quot; onMouseOut=&quot;imgOff('img1')&quot;>
</form>

<script LANGUAGE=&quot;JavaScript&quot;>
if (document.images) {
// MouseOver Images
img1on = new Image();
img1on.src = &quot;submitON.gif&quot;;
// MouseOut Images
img1off = new Image();
img1off.src = &quot;submit.gif&quot;;
}
function imgOn(imgName) { if (document.images) {
document
.src = eval(imgName + &quot;on.src&quot;);
}}
function imgOff(imgName) { if (document.images) {
document
.src = eval(imgName + &quot;off.src&quot;);
}}
</script>
 
document.images
.src = eval(imgName + &quot;on.src&quot;);

document.images
.src = eval(imgName + &quot;off.src&quot;);
 
Kevin, I tried subsitituting document.images
.src = eval(imgName + &quot;on.src&quot;); for document
.src = eval(imgName + &quot;on.src&quot;);

I just get the same error. If I were using the <IMG> tag wrapped in <A></A>, everything works. The code just won't run on the <INPUT> tag.
 
Why don't you use <A></A> so?

<a href=&quot;javascript:document.formName.submit()&quot; onMouseOver=&quot;imgOn('img1')&quot; onMouseOut&quot;imgOff('img1')&quot;><img src=&quot;submit.gif&quot; name=&quot;img1&quot; ... alt=&quot;submit&quot;></a>

Replace the &quot;formName&quot; with an actual name of your form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top