2

I'm working on a site where I have input buttons (styled using CSS) that are a part of a form. For example, see below for sample code

<input type="submit" name="buttonSave" value="save" id="buttonsavejs" class="button_image button_style"/>

I've just found an issue where if a user clicks on the button, it moves a few pixels below and then expected action takes place intermittently. But intermittent, I mean that sometimes it works (redirects the user to the next page) and sometimes nothing happens.

The developer who worked on this previously hasn't documented his code much, so I'm trying to work from scratch here (so excuse the lack of details). Anyway, after testing the code, it appears that the issue lies with how newer browsers are rendering the css and javascript.

Here's a snippet of the javascript behind the button's functionality:

$("#buttonsavejs").click(function(){
        $("#main").unbind("submit").submit();

And the CSS that styles the button

.button_style {
  height:28px;
  margin-left:10px;
  position:relative;
  right:10px;
  top:-23px;
  width:100px;
}

.button_image {
  background-image:url(http://some_image);
  border-bottom-width:0;
  border-color:initial;
  border-image:initial;
  border-left-width:0;
  border-right-width:0;
  border-style:initial;
  border-top-width:0;
  display:block;
  font-size:1px;
  line-height:1px;
  outline-color:initial;
  outline-style:none;
  outline-width:initial;
  overflow-x:hidden;
  overflow-y:hidden;
  position:relative;
  text-indent:-9999px;
}

Also, I noticed a very similar question asked here: Why do mouse clicks not always work for styled input buttons?

Another piece of what I've been able to find out so far. In IE 9's developer tools, if I switch the Document Mode to anything other than IE 8 or 9, the button behaves as it should. So one line of thinking I have is to set the X-UA-Compatible to IE 7 and see if that resolves it as, apparently, that's how the document mode in IE works: IE8 browser mode vs document mode

Question: After testing in FF (earlier versions < 9.0), IE 7, I noticed that the button works as it should. But in FF 9, Chrome 16, IE 8/9, it behaves as described above. Has anyone run into a similar problem and any advice on what I should be watching out for?

Community
  • 1
  • 1
Ray
  • 3,409
  • 8
  • 33
  • 40
  • The answer posted to that question seems to point you in the right direction (the `position: relative` stuff). What have you done to explore that? – T.J. Crowder Jan 12 '12 at 18:33
  • Just curious, why are you resetting initial values to `initial` here? Do you set them to other values for more general styles? – BoltClock Jan 12 '12 at 18:34
  • @BoltClock: Not sure why it was coded this way. But I don't think this is connected to the issue. – Ray Jan 12 '12 at 18:40
  • @T.J.Crowder: I tested it using IE's developer and firebug and it doesn't seem to make a difference in this case (even if I remove it completely). – Ray Jan 12 '12 at 18:43
  • i have a similar issue. i also beleive it is FF browser version issue: http://stackoverflow.com/questions/8845536/jquery-min-conflict-with-input-submit – othman Jan 13 '12 at 04:39
  • Maybe an unbind issue? Have you tried swapping a normal submit button with a javascript-created button, once the page loads, so you can leave the unbind out? It would then fall back to the more button if javascript isn't switched on. – Deadlykipper Jan 18 '12 at 17:03
  • are there styles for this input that affect the :active pseudo-selector? .button_image:active or .button_style:active ? if there is any positioning on that, then it will cause your issue. – Scottux Jan 23 '12 at 02:19
  • 1
    Why do you need to unbind the submit event? – j08691 Jan 23 '12 at 21:09
  • Try getting rid of all superfluous styling in .button_image which may trigger bugs. I'd start getting rid of the position:relative and the unnecessary display:block, simplify all borders to "border:none;", overflow-x+y to "overflow:hidden;". Change text-indent to -999em. Then see. – GlennG Jan 26 '12 at 20:50
  • wow thats some ugly css right there! 'border:none;'? :) And I'd start by blaming jQuery – Marc Costello Jan 27 '12 at 14:42

1 Answers1

0

Easy fix:

first, don't use :

<input type="button" />

use

<button type="button">bla bla bla</button> // you can use type="submit"

and in script :

$("#buttonsavejs").click(function(e){
    e.preventDefault(); // this stops the button from doing it's default action, aka submit.
Bart Calixto
  • 19,210
  • 11
  • 78
  • 114