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

Auto-fill input field with URL parameter values using JavaScript or jQuery

I am in possession of a URL http://www.example.com/state=survey&action=display&survey=39&zone=surveys&currency=Denmark Upon accessing the above link, a user will be directed to a new page containing a form. Within this form, there is an i ...

Change the border color of a form field in a material design if the user interacts with the

Is there a way to change the border color of a material form field in Angular when it is touched, focused, or active? I attempted to modify the color by overriding material css-class and also tried creating my own css class, but neither method had any ef ...

Show the combined cost and dimensions of products depending on the quantity and type of product in WooCommerce

Thank you for your patience with me as I continue to learn and improve my coding skills. The assistance I've received so far has been invaluable, and I truly appreciate it. I currently have a code snippet that calculates the amount of fabric being pu ...

I am facing an issue where the auto-generated jQuery click event is not functioning as expected

Appending the table row in a different way: $('#selectStudents').append("<tr><td>"+rollno+"</td>\n\ <td>"+name+"</td>\n\ <td><a href='#' class='att-time-btn toggl ...

In ReactJS with Bootswatch, the font styles are not applied

I have experimented with various methods to apply this font, but it is still not functioning correctly. @font-face { font-family: 'Samim'; src: local('Samim'), url(./resources/fonts/Samim.ttf) format('truetype'); fon ...

What is the method for activating the on collapse event with a bootstrap navbar?

I am encountering a common issue with collapsing the navbar on smaller screens and triggering an event when the collapse button icon is clicked. Despite my efforts to find a solution, I have been unsuccessful in using the following JavaScript code: $(&apos ...

Struggling to insert a high-quality image into inline divs of exactly 33.3333% width

After creating 3 inline divs, each taking up 33.333% of their parent width, I encountered an issue while trying to insert images into them. Whenever the image exceeds the 33.333% width of the div, it overflows outside the container. My goal is to make the ...

What is the best way to retrieve the ID of the input element using a jQuery object?

After submitting a form with checkboxes, I retrieve the jQuery object containing the checked input elements. var $form = $(e.currentTarget); var $inputs = $form.find("input.form-check-input:checked") Here is an example of how the inputs are stru ...

Updating Page Content with JQuery AJAX Post Without Page Reload

So I realize I may be asking a question that has been asked before, but as a complete beginner with AJAX jQuery, I'm not sure what to search for. I've tried searching without success, so please bear with me. I have a PHP WordPress site that defa ...

Remove the initial section of the text and provide the rest of the string

I am a beginner in the world of Javascript and unfortunately I have not been able to find an answer to my current problem. Here is the situation. On a webpage, I am receiving a URL that is sometimes presented in this format: http://url1.come/http://url2.c ...

How to retrieve the chosen value from a dropdown list using jQuery and PHP

I am having trouble with a drop down menu <div class="form-group"> <select class="form-control" required name="uname" id="uname"> <option value=""/>Select Your Name</option> <?php foreach ($this->getallusers as $users): ...

Plugin for turning text into "leet speak" using jQuery and Javascript

Recently, I've been on the hunt for a 1337 translator that I can seamlessly integrate into a jQuery plugin. While I believe I'm making progress, I can't shake off the feeling that something's amiss. My gut tells me that what I currently ...

Issue with the format of incoming data in Ajax post request when working with Django framework

Hello everyone, I am currently working on a script to send a post request to my Django backend. My goal is to have the data in Json format. <input id ="my" type="submit" onclick="me()"/> <script> function me() { var data2 =JSON.stringif ...

Angular dynamically filling in a table with incomplete object data

I am currently working on a scientific project that involves displaying large amounts of data in tables. The experiments I'm working with have timestamps that follow this format: interface TimeData { time: string; data: {SD: string, SEM: string ...

Modifying the appearance of Bootstrap button colors

I recently came across this code on the Bootstrap website. I am curious about how to change the text color from blue to black in this specific code snippet. Currently, the text is appearing as blue by default. For reference and a live example, you can vis ...

Can you generate a new element based on a template element?

I'm encountering an issue with the following code snippet: template = $("#template"); $(template).attr("id", "newid"); $(template).appendTo("body"); My goal is to assign an id to the template and then modify its content. However, I seem to be direc ...

Using JQuery to swap out all URLs on a webpage?

Seeking guidance and examples on replacing all the links in the head of a document using jQuery. I am currently working with an app that requires my site to have SSL. To address this requirement without purchasing an SSL certificate or a static IP, I am a ...

jquery line break in textarea

There is a 'edit description' button that, when clicked, makes text disappear and reappear if (id == 'commedit') jQuery(this).html('<textarea>'+jQuery(this).text()+'</textarea>'); else i ...

JavaScript integration is a key aspect of working with Rails 3.1, especially when utilizing JQuery

I've been searching for a clear answer to this issue and I know I'm not the only one stressing about it. Current best practices suggest placing javascripts at the bottom of the page. However, any blocks that use proper $(function() {...}); will ...

Modify the appearance of the username in the header after logging in with Yii

As a fellow coder using Yii, I'm seeking assistance in changing the style of my username displayed in the header upon login. Currently, it's appearing in black color and I desire it to be italicized-white. The code snippet below shows my header s ...