Jump to content

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
https://forums.phpfreaks.com/topic/49454-solved-driving-me-mad-onkeypress/
Share on other sites

I've given up and changed it to a submit.

 

If anyone's interested, it's to do with the fact that images don't have events in the same way as submits (ref nogray).

 

This article might help you (but it didn't help me): http://www.thescripts.com/forum/thread338775.html

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.

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.