1

i'm using a form which contains a "send" button and a "delete" button.

Once the page is loaded it's seems like this 'delete' button is "selected" - i.e - it's wrapped by a blue line and also when pressing on "enter" the js function that's is called when this button is clicked is fired.

In firefox and chrome it works just fine, what could I do so when the page is loaded this button won't be in a "selected" mode?

*The delete button is the first button appeared in the page , and I fount out that IE highlights the first button in the page for some reason . How could I disable this setting ?

Thanks in advance

Itamar
  • 524
  • 1
  • 9
  • 21

2 Answers2

0

try appending this to your script:

(function(w)
{
    if (w.attachEvent)
    {
        w.attachEvent('onload',function tmpLoad()
        {
            document.body.focus();
            //or document.getElementById('submitId').focus(); to focus submit btn
            w.detachEvent('onload',tmpLoad);//detach listener, too
        });
        return;
    }
    //if this issue occurs with IE > 8:
    if (navigator.appName === 'Microsoft Internet Explorer')
    {
        w.addEventListener('load',function tmpLoad()
        {
            document.body.focus();
            w.removeEventListener('load',tmpLoad,false);
        },false);
    }
})(this);

That should work. Though this isn't easy to work out in a fiddle, here's one, tested in IE, button wasn't selected.

Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
0

try this:

<form>
<input name="Delete_btn" type="button" onclick="$(this).parent('form').append('<input type=hidden name=Delete value=Delete />').submit();" value="Delete" id="Delete_btn" />
<input type="text" name="f1" id="f1" />
<input name="Submit" type="submit" value="Submit" id="Submit" />
​</form>

http://fiddle.jshell.net/d8xWB/2/show/

Ghassan Elias
  • 2,213
  • 1
  • 14
  • 17
  • No jQuery tag, and (I think) Not an answer to the question. – Elias Van Ootegem Aug 28 '12 at 09:35
  • yes no jQuery tag, but he need a solution. he might find your answer useful. but this is not IE only problem, for example your script wont work on safari or other browsers. – Ghassan Elias Aug 28 '12 at 09:41
  • `because it's only relavant to internet explorer which highlights the first button in the page` <-- it's an IE only problem. I'm currently working in chrome and FF, there's no need for the script there. My suggestion doesn't interfere with any of the other code (it's contained nicely inside a function scope) and only does stuff when its running on an IE browser. The problem, AFAIK, is that the delete button is selected on page load in IE, your suggestion doesn't address that – Elias Van Ootegem Aug 28 '12 at 09:53
  • If my script should work in all browsers, the `if(navigator.appName...)` branch should be replaced with `if (w.addEventListener)` and it'll work on _all_ browsers flawlessly, without the necessity of jQuery. jQ is a good toolkit, but I feel it's not justifiable to use it just for this one glitch – Elias Van Ootegem Aug 28 '12 at 09:56
  • man your solution is so lame! you are removing the focus from the button. but when you fill the form and press enter the delete button will be fired. check your code in action: http://jsfiddle.net/d8xWB/10/ here's the page: http://fiddle.jshell.net/d8xWB/10/show/ you should get downvote – Ghassan Elias Aug 28 '12 at 09:58
  • FFS, of course it does, you've set the type to `submit` on that fiddle, in your case its type is `button`. `submit` buttons have the default behaviour on enter to submit, and `delete` is the first submit available. Instead of calling my take _lame_ and _down-vote-worthy_ at least write decent markup, and do your homework – Elias Van Ootegem Aug 28 '12 at 10:07
  • I know what submit button can do. so if we take your script and put the type of the delete button to `button` how can a user submit the form when he click the delete button? can you please send us the Fiddle link? – Ghassan Elias Aug 28 '12 at 10:25
  • Now look, your snippet has a `button` (delete) and a `submit` input, all you're doing is making the `delete` button act as a duplicate of the submit button. If that were the OP's question, there's nothing stopping me from adding an event listener to the delete button, is there? I could even add a keypress listener to the window to submit when the user types `foobar`, if I wanted to... Grow up, and let it go – Elias Van Ootegem Aug 28 '12 at 10:30