Submit rollover button that works in MOZ and IE

HI, I have been having this big problem.
I made some rollovers in CSS and they don't work in MOzillia, so I tried javascript rollovers, the problem is that the javascript rollovers is when I the form is submitted I have it validate the input box fields but the javascript code for the form validatation does not execute when I use javascript rollovers.

Is there a simple way I can have a rollover that acts like a submit button that will work in both Mozillia and IE?
Andrew99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

J-MikCommented:
Andrew99,

Just create an a normal IMG rollover and add something along these lines: onClick="if (MyValidationFunction) submit()";
0
Andrew99Author Commented:
What do you mean by normal img rollover?
0
Andrew99Author Commented:
can you give me a example of a simple image rollover?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

dakydCommented:
Will something like this work?  I created a very simple form, with an input of type image.  When you click on this image, the form submits to the same page.  You can tell the form submitted because you'll see "hiddenInput=peek-a-boo" in the URL/query string.  As for the roll over effect, you can achieve it with a bit of CSS.  The only javascript you need is to make up for IE's poor implementation of the CSS, so that you can have your mouseover/mouseout effect.  Obviously the styling is very simple, but you can change it however you need.  Hope that helps.

<!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<style type="text/css">
#theImg {
  border: 0;
  height: 50px;
  width: 50px;
}

#theImg:hover, #theImg.myHover {
  border: 1px solid blue;
  padding: 2px;
  background-color: #bdb;
}
</style>
<script type="text/javascript">
window.onload = init;

function init()
{
  var obj = document.getElementById("theImg");
  obj.onmouseover = function() {this.className = "myHover";};
  obj.onmouseout = function() {this.className = "";};
}
</script>
</head>

<body>
<form id="formToSubmit" name="formToSubmit" method="get">
  <input type="hidden" name="hiddenInput" value="peek-a-boo" />
  <input type="image" src="smiley.jpg" id="theImg" />
</form>
</body>
</html>
0
J-MikCommented:
Andrew99,

Here's a sample of a simple image rollover:

<SCRIPT TYPE="text/javascript">
<!--

  var ImgOff = new Image();
  var ImgOn = new Image();
 
  ImgOff.src = "SomeOffImage.jpg";
  ImgOn.src = "SomeOnImage.jpg";

//-->
<SCRIPT>

<IMG ID="MyImg" SRC="SomeOffImage.jpg" onMouseOver="document.getElementById('MyImg').src = ImgOn.src;" onMouseOut="document.getElementById('MyImg').src = ImgOff.src;">


...And then of course, you can add the onClick code as well. Let me know if you have any problems with this.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andrew99Author Commented:
I need the submit to submit as post and not like a Get which shows up the in query string.
0
dakydCommented:
Change the <form> tag's method to "post".  The <input type="image" ...> tag will submit the form the same way that <input type="submit" ...> would - you still have to define a method and an action for the form itself.  I used the "get" method to illustrate that it does in fact submit, but there's no reason why you can't change it to "post".  Hope that helps.
0
Andrew99Author Commented:
Dakyd your code is good excpet how do i implement the rollover?
0
dakydCommented:
What exactly do you want to happen when you mouse over the image?  I assumed (maybe incorrectly) that you just wanted to style the image, rather than change the image.  If that's the case, then all you have to do is use my last post and add your styling to the CSS block for #theImg:hover and #theImg.myHover.

However, if you want the picture to change, then you essentially use J-Mik's code.  To change the image when you mouseover it, you want something like the following.  Take out the hidden input if you don't need it, and you'll notice that I changed the method to "post" this time.  I also styled the image to be 100px by 100px, but that's also not necessary, you can take it out or adjust the dimensions however you want.  Either way, hope that helps.

<!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<style type="text/css">
#theImg {
  height: 100px;
  width: 100px;
}
</style>
<script type="text/javascript">
window.onload = init;

img1 = new Image();
img2 = new Image();
img1.src = "sad.jpg";     // PUT YOUR ONMOUSEOVER IMAGE SRC HERE
img2.src = "smiley.jpg"; // PUT THE ORIGINAL IMAGE SRC HERE

function init()
{
  var obj = document.getElementById("theImg");
  obj.onmouseover = function() {this.src = img1.src;};
  obj.onmouseout = function() {this.src = img2.src;};
}
</script>
</head>

<body>
<form id="formToSubmit" name="formToSubmit" method="post">
  <input type="hidden" name="hiddenInput" value="peek-a-boo" />
  <input type="image" src="smiley.jpg" id="theImg" />
</form>
</body>
</html>
0
Andrew99Author Commented:
J-Mik you gave me exactily what I was looking for something nice and simple!

And it worked.  I just put the onMouseOver="document.getElementById('MyImg').src = ImgOn.src;" onMouseOut="document.getElementById('MyImg').src = ImgOff.src;"

in the input box using the javascript code and everything fit together so perfect!

Thanks for your help.
0
J-MikCommented:
Glad I could help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.