Changing the color of div on "enter click"?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Changing the color of div on "enter click"?

Post 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>
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply