Issue with rollover button function in Firefox and Internet Explorer when attempting to submit

I have created a rollover submit button using HTML and JavaScript:

<input type="image" id="join" name="join" src="images/join.png" value="join">

My JS code implements the rollover/hover effect:

<script type="text/javascript" charset="utf-8">
            $(document).ready(function(){
                $('#join').hover(
                    function(){ 
                        $(this).attr({ src : 'images/rollover/joinOver.png'});
                    },
                    function(){ 
                        $(this).attr({ src : 'images/join.png'});                }
                );
            });
        </script>

However, this functionality works flawlessly in most browsers but encounters issues with Firefox and IE. Surprisingly, when I include a standard "submit" button (input type = "submit"), it performs well across all platforms.

I attempted to modify the HTML by changing the type attribute to "submit" and experimenting with CSS for hover image effects both inline and through class in external stylesheets, but unfortunately, that didn't resolve the problem.

Is there a reliable method to create a rollover button that operates consistently on every browser? (I've tested it on Chrome, FF, IE, Opera, Safari)

NOTE:

To clarify, my challenge lies not in designing a rollover image but in developing one that functions as a "submit" button for a form to trigger a PHP script.

While my code demonstrates the rollover effect in various browsers, it doesn't fulfill its purpose as a "submit" button specifically in FF and IE.

Answer №1

take a look at this:

http://jsfiddle.net/LcnrJ/3/

Here is the HTML code snippet:

<input type="submit" class="join" value="SEND"/>

And here is the jQuery code snippet:

$(document).ready(function(){
    $(".join").hover(function(){
        $(".join").toggleClass("newphoto");
    });
});

Answer №2

Compatibility Test Results

Testing was conducted on both Internet Explorer 8 and Firefox 24 browsers. During the test, the image sources for 1.jpg and 2.jpg were modified, along with the action parameter being set to "".

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
 <html><head>
 <title>Form Test</title>
 <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
 <script language="JavaScript" type="text/javascript">
<!-- Hide from old browsers
 
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
 // unhide -->
</script>
 </head>
 <body bgcolor="#FFFFFF" onLoad="MM_preloadImages('1.jpg')">
 <form action="" method="POST">
 <input type="image" src="2.jpg" border="0" id="submitbutton" onMouseOver="MM_swapImage('submitbutton','','1.jpg',1)" onMouseOut="MM_swapImgRestore()">
 </form>
 </body>
 </html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue encountered while trying to update field using dynamically created row

I am encountering a problem while trying to update the unit cost and total cost of dynamically generated rows in an inventory form that submits inventories to a database. The product names are fetched via autocomplete jQuery, as shown in the snapshots belo ...

Implement a vertical background sprite animation using jQuery along with a mask

Is it possible to create a jQuery background vertical animation that smoothly transitions the sprite position, giving the appearance of fading into the next position? Currently, my code (view demo jsfiddle link below) moves the sprite to the correct backgr ...

I wish to trigger the function when the button with the ID "add_city" is clicked instead of it being activated upon pressing the Enter key as it currently is

Is it possible to trigger the function by clicking a button with the id "add_city", rather than just pressing Enter? function createCity(stateId, newCity, event) { if(event.keyCode == 13 || $(this).attr('id') === 'add_city') { i ...

The offspring surpasses the parent's limits and extends beyond its

I am designing a webpage layout that includes 2 navigation bars (top), a top-graphic (middle) flexbox, and a content flexbox (bottom). Within the top-graphic flexbox, I want to add a black box for text. However, I am facing issues with the box overflowing ...

Employing jQuery for element rotation via swipe/drag movements

I am looking to create a dynamic experience where a circle rotates in sync with the user's swipe or drag gestures on the screen. Currently, I am developing an app using Phonegap and considering integrating hammer.js as it comes highly recommended by m ...

Identify the currently active subitem within the item-active class in a PHP carousel slider

I am working on creating an image carousel slider with 4 items and 4 slides each. These images will act as radio buttons, and I want to highlight the slide corresponding to the selected radio button. So, when the carousel loads, the selected slide should b ...

If the blank option is chosen, then proceed to select option 3

Appreciate any assistance on this matter. In our dropdown menu, there is an empty option at the top. <select id="Flags"> <option></option> <option value="Corporate">Corporate.png</option> <option value="Store2">Store2 ...

How can you utilize jQuery to iterate through nested JSON and retrieve a specific matching index?

In the scenario where I have a nested JSON object like this: var library = { "Gold Rush": { "slides": ["Slide 1 Text","Slide 2 Text","Slide 3 Text","Slide 4 Text"], "bgs":["<img src='1.jpg' />","","<img src='2.j ...

Load a form using ajax and submit it using jQuery

For a while now, I have been facing challenges in figuring out what's going wrong with my code. The issue arises when I try to submit a form using jQuery that was loaded through ajax. The form loads perfectly fine within a div after invoking the ajax ...

What is the best way to display a div box only when a user checks a checkbox for the first time out of a group of checkboxes, which could be 7 or more, and then hide the

Is there a way to make a div box appear when the user checks any of the first checkboxes? I have attempted using the following codes: JQ Codes: $('#checkbox').change(function() { if ($(this:first).is(':checked')) { cons ...

Is there a method to initiate the Jquery Dialog without needing to use the .dialog registration function?

I am currently facing an issue with my page that contains multiple tabs. These tabs are loaded dynamically and one of them is a message container for mail. Every time I click on a folder link (such as Inbox or Sent Mail), only that specific tab gets reload ...

The issue of CSS Grid not adapting fully to different screen sizes and

Recently, I took on a coding challenge from Frontend Mentor (this one) and managed to complete it successfully. However, the grid I designed is not fully responsive. It only adapts correctly when the page width matches the media query specifications. The c ...

List on the Left Side with Scroll Capability

In my ASP.NET web application that targets .NET 3.5 and utilizes an AJAX asp:UpdatePanel, I have structured the page layout using multiple div elements to divide the vertical space into sections - header, first content, second content, third content, and f ...

Deciphering the intricacies of the http request

I encountered an issue while trying to send a POST request using jQuery AJAX. Upon making the request, I received the following error: XMLHttpRequest cannot load. Response for preflight has invalid HTTP status code 403 Now, I am unsure if the mistake i ...

Challenges with resizing images in SVG using D3

I have an SVG image created using d3. I am facing an issue where the svg is extending beyond its parent div container. Here is the code snippet: <div id="test" style="{width: 500px; height:500px;}"> <svg></svg> </div> ...

The background color in CSS remains stagnant, refusing to change despite

Can someone help me figure out why the background color isn't changing in my simple code? I've double-checked that the external CSS is properly linked because the text color of h1 is changing. <!DOCTYPE html> <html> < ...

What are the steps to incorporating ng2-dnd with a background-image?

I am currently utilizing the ng2-dnd module to enable sorting of a list. While the functionality for sorting and dragging is working smoothly, there's one issue - users can only drag by clicking on the text within my element. My goal is to allow user ...

Updating Github pages requires clearing the cache first

As I work on my first website using GitHub pages, I've noticed that it can be frustrating to constantly clear the cache or open an incognito window whenever I add something new. I'm thinking about incorporating Jekyll into my workflow so I can t ...

stop unauthorized entry to the jquery post URL

I have a jQuery script that sends data to a .php script using post or get methods. However, I want to prevent direct access to the PHP script. If a user looks at the HTML source code, they could potentially access the PHP script by copying the URL from ...

Obtain a collection of chosen dates from the availability scheduler

I am currently working on an availability calendar where users can select multiple dates. While I have successfully been able to retrieve the value of each individual cell, I am facing difficulty in getting an array of values for all the cells selected. ...