views:

57

answers:

4

I am creating an HTML contact form that uses a standard image for a submit button.

Here is the html:

<form action="#">
    <fieldset>
        <input type="text" name="name" value="FULL NAME" onfocus="if (this.value=='FULL NAME') this.value='';"/>
        <input type="text" name="" value="PHONE NUMBER" onfocus="if (this.value=='PHONE NUMBER') this.value='';"/>
        <input type="text" name="" value="EMAIL" onfocus="if (this.value=='EMAIL') this.value='';"/>
        <input type="text" name="" value="MOVE DATE" onfocus="if (this.value=='MOVE DATE') this.value='';"/>
        <input type="text" name="" value="ORIGINATING ADDRESS" onfocus="if (this.value=='ORIGINATING ADDRESS') this.value='';"/>
        <input type="text" name="" value="DESTINATION ADDRESS" onfocus="if (this.value=='DESTINATION ADDRESS') this.value='';"/>
        <select name="type">
            <option value="Private">Private</option>
            <option value="Commercial">Commercial</option>
        </select>
        <input id="quoteSubmit" type="image" src="_images/btn_submit.png" alt="" />
    </fieldset>
</form>

The static Submit button image is okay, but I would like change it on mouseover to btn_submit-over.png.

I am familiar with mouseovers useing css sprites, but they don't work for submit buttons. I would appreciate some help.

Thanks!

+2  A: 

You can do this several ways... with jquery might be the best way, but this is how you do it without.

Change
<input id="quoteSubmit" type="image" src="_images/btn_submit.png" alt="" />

to
<input id="quoteSubmit" type="image" src="_images/btn_submit.png" alt="" onmouseover="javascript:this.src='_images/btn_submit-over.png'" onmouseout="javascript:this.src='_images/btn_submit.png'"/>

Just from the top of my head, I guess that should work.

Br, Paul

Paul Peelen
Highly unlikely, also no need for javascript: unless there is VBScript on the page as the first script
mplungjan
Drat, it actually works in FF3.6, IE8, Chrome and Safari on Windows. My apologies
mplungjan
Works perfectly. Thanks.
fmz
Glad I could help! :)yw
Paul Peelen
@Paul: There shouldn't be the `javascript:` in the event handler.
KennyTM
@KennyTM: Correct, but then again... it doesn't hurt either. It work both with and without.
Paul Peelen
A: 

OldSchool:

        <a href="#" onclick="document.forms[0].submit(); return false"
onmouseover="document.subBut.src=document.subBut.src.replace('.png','over.png')"
onmouseout="document.subBut.src=document.subBut.src.replace('over.png','.png')"><img 
name="subBut" src="_images/btn_submit.png" alt="" border="0" /></a>
mplungjan
A: 

Wouldn't it be possible to use a class?

<input type="submit" class="submit" .../>

CSS:
input.submit:hover{
   color: Green;
} 

or you could use then a little JavaScript to handle the swapping of images and to cause the button to call submit() (javascript:document.theform.submit())

Daniel Frear
+2  A: 

With pure CSS,

<input type="submit" value="::Submit Query::" id="foo" />

...

  #foo {
    background-image: url('_images/btn_submit.png');
    width: <width here>;
    height: <height here>;
    border-style: none;
    background-color: transparent;
    text-indent: 480px;    /* hack to hide the text */
  }

  #foo:hover {
    background-image: url('_images/btn_submit-over.png')
  }

If CSS is disabled it will revert to a simple submit button.

Demonstration: http://jsbin.com/aboxu3/2

You could then apply the CSS sprite techniques.

KennyTM
Much nicer than script. Cool site, jsbin btw
mplungjan
http://stackoverflow.com/questions/195632/how-to-change-input-button-image-using-css
mplungjan