Jump to content

[SOLVED] Driving me mad - onkeypress


marmite

Recommended Posts

Hi,

 

Can anyone tell me what's wrong with this code:

 

<input type="image" src="images/loginbutton.gif" onKeyPress="alert('hello');" id='loginbutton' name='loginbutton' width="80" height="17">

 

I've tried various " and ; variations. All I want is a pop-up when the user hits enter (it will tell them that they need to press the button)

 

Going mad ???

Link to comment
Share on other sites

The image type doesn't have an onKeyPress event because it doesn't take any input.

 

Use onClick instead.

 

If you want the alert to show when the user click the enter button, add it to the onsubmit event in the form.

Link to comment
Share on other sites

Thanks for the replies: onKeyDown doesn't work, either.

 

OnClick does work but it isn't what I want - it pops up when people click the button: I want instead a pop-up when someone hits enter.

 

Grateful for any ideas...

Emma

Link to comment
Share on other sites

Here is a quick demo on alerting using an image button (using the onsubmit event on the form)

<form onsubmit="alert('hello');">
<input type="text" />
<select><option>Select</option></select>
<textarea></textarea>
<input type="image" src="image_src" alt="submit" />
</form>

Notice the enter button only submit the button when it's clicked on the input type="text", it doesn't work from a select menu or a textarea.

 

You also can use a submit button if you want, just use CSS to add a background image, remove the borders and set the height and width. This will give you a graphical submit button.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.