Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 737
  • Last Modified:

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
0
macuser777
Asked:
macuser777
  • 4
  • 3
1 Solution
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now