Combine OnClick submit with button rollover

Hi,

I want to make some sumbit buttons use rollover images

I have this javascript for rollover

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

image1 = new Image();
image1.src = "http://www.mydomain/imageroll1.gif";

image2 = new Image();
image2.src = "http://www.mydomain/imageroll2.gif";


</script>
</HEAD>


<BODY>

<a href="http://google.com" onmouseover="image1.src='http://www.mydomain/imageroll1.gif';"
onmouseout="image1.src='http://www.mydomain/imagestatic1.gif';">
<img name="image1" src="http://www.mydomain/imagestatic1.gif" border=0></a>

<a href="http://msn.com" onmouseover="image2.src='http://www.mydomain/imageroll2.gif';"
onmouseout="image2.src='http://www.mydomain/imagestatic2.gif';">
<img name="image2" src="http://www.mydomain/imagestatic2.gif" border=0></a>

</BODY>

-------

And these OnClick Submits

  <input type="hidden" name="keywords">
  <input type="hidden" name="c" value="1">
   <input type="hidden" name="index" value="0">

<input type="text" name="search"  value="" style='width:252px' maxlength="255">

              <input name="submit" type="submit" style="width:120;text-align:center" onClick="this.form.keywords.value = this.form.search.value; this.form.action = ' http://www.mydomain.com/searchq.php ';" value="Search1">

              <input name="submit" type="submit" style="width:120;text-align:center" onClick="this.form.keywords.value = this.form.search.value; this.form.action = ' http://www.mydomain.com/searchq.php';"  value="Search2">    

</form>

I need to keep this form of submit.

Any good javascript rollover will be fine.

Thanks
LVL 4
macuser777Asked:
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.

dakydCommented:
How about something like this?  An input with type of image is like a submit button, but lets you include a src for the image, so you can do your rollovers.  Hope that helps.

<html>
<head>
<script type="text/javascript">
image1 = new Image();
image1.src = "http://www.mydomain/imageroll1.gif";

image2 = new Image();
image2.src = "http://www.mydomain/imageroll2.gif";

window.onload = initSubmit;

function initSubmit()
{
  var els = document.theForm.getElementsByTagName("input");
  for (var i = 0, n = els.length; i < n; i ++)
  {
    if (els[i].name == "submit1")
    {
      els[i].onmouseover = function() {this.src = image1.src;};
      els[i].onmouseout = function() {this.src = "http://www.mydomain/imagestatic1.gif";};
    }
    else if (els[i].name == "submit2")
    {
      els[i].onmouseover = function() {this.src = image2.src;};
      els[i].onmouseout = function() {this.src = "http://www.mydomain/imagestatic2.gif";};
    }
  }
}
</script>
</head>

<body>
<form name="theForm" id="theForm">
  <input type="hidden" name="keywords">
  <input type="hidden" name="c" value="1">
  <input type="hidden" name="index" value="0">

  <input type="text" name="search"  value="" style='width:252px' maxlength="255">
  <input type="image" name="submit1" src="http://www.mydomain/imagestatic1.gif" style="width:120;text-align:center" onClick="this.form.keywords.value = this.form.search.value; this.form.action = ' http://www.mydomain.com/searchq.php ';" />
  <input type="image" name="submit2" src="http://www.mydomain/imagestatic2.gif" style="width:120;text-align:center" onClick="this.form.keywords.value = this.form.search.value; this.form.action = ' http://www.mydomain.com/searchq.php';" />
</form>
</body>
</html>
0
macuser777Author Commented:
hmmm...no.

Didn't rollover ...and I van't use submit1, submit2 etc because that causes redirect errors with my code.

Is there any way to do it more simply by just adding OnMouseover into the submit line....like in first instance below.?

 <form method="get">
          <input type="hidden" name="keywords">

          <input type="hidden" name="c" value="1">
          <input type="hidden" name="index" value="0">
          <input type="text" name="search"  value="" style='width:252px' maxlength="255">

              <input name="submit" type="image"  src="http://www.isearch.com/roll/o3.png" align="absmiddle"  onClick="this.form.keywords.value = this.form.search.value; this.form.action = ' http://www.isearch.com/searchq.php ';" value="Web Search" onMouseOver="src=http://www.isearch.com/roll/o5.png">

              <input name="submit" type="submit" style="width:120;text-align:center" onClick="this.form.keywords.value = this.form.search.value; this.form.action = ' http://www.isearch.com/searchq.php';"  value="blah">
          </form>
0
dakydCommented:
Yes, you can use the code inline on the input itself.  I prefer not to do it that way, but it's valid.  Using what you posted, here's the example on the first image.  Didn't know what image you wanted as the roll over for the second one, so I left it blank.  It's the same idea, though, just change the src onmouseover, and change it back onmouseout.  Hope that helps.

<form method="get">
  <input type="hidden" name="keywords" />

  <input type="hidden" name="c" value="1" />
  <input type="hidden" name="index" value="0" />
  <input type="text" name="search"  value="" style='width:252px' maxlength="255" />

  <input name="submit" type="image"  src="http://www.isearch.com/roll/o3.png" align="absmiddle"  onclick="this.form.keywords.value = this.form.search.value; this.form.action = ' http://www.isearch.com/searchq.php ';" value="Web Search" onmouseover="this.src='http://www.isearch.com/roll/o5.png';" onmouseout="this.src='http://www.isearch.com/roll/o3.png';" />

  <input name="submit" type="submit" style="width:120;text-align:center" onclick="this.form.keywords.value = this.form.search.value; this.form.action = ' http://www.isearch.com/searchq.php';"  value="blah" > 
</form>
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
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.

macuser777Author Commented:
Thanks, dakyd

That works fine. I don't really understand javascreipt so simpler is probably better for me.

macuser
0
macuser777Author Commented:
errr...can I put align="abs middle" or some inline style attribute in there?
0
macuser777Author Commented:
hold the phone....not actually submitting....
0
dakydCommented:
Posted the sample here, it works fine for me:
http://www.freewebs.com/dakyd/ee/test.html
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.