Page 1 of 1

Changing the color of div on "enter click"?

Posted: Mon Oct 04, 2010 5:38 am
by dominod
Hi,

I am a javascript newbie and wonders how to do this:

I want to change this:

Code: Select all

.buttons a, .buttons button{
    background-color:#f5f5f5;
to this

Code: Select all

.buttons a, .buttons button{
    background-color:#000000;
when enter is clicked when the form field is focued (to make it behave like a button).

Anyone knows how to do this?

This is the code for the button BTW:

Code: Select all

<div class="buttons">
    <a href="#" onclick="this.blur();parent.document.forms[0].submit();">
Search
    </a>
</div>
</form>

Re: Changing the color of div on "enter click"?

Posted: Mon Oct 04, 2010 9:58 am
by pickle
Attach a keyup() listener to the field, and check the keyCode that is passed. If it matches "Enter" or "Numpad Enter", set the background color.