Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessKey for an IMG element

Status
Not open for further replies.

bobmm

Programmer
Nov 20, 2000
41
GB
Hi..

Target Browser IE5

I am trying to implement keyboard shortcut keys using the accessKey="" property. All is well until I try this with an Image element..I have tried to wrap the image in a DIV and a SPAN, and using a LABEL but still no luck...any ideas anyone?

Thanks...
 
have you tried using an ID for the img ??
<img id=whatever ...>
and then document.all.whatever
 
Thanks iza, I've got round it using the following...

Where the accelerator key triggers the set focus event on an image, as opposed to the click event, using the onfocus event in a little scriplet does the job...Yeh...I know it could be better, but it works OK....

Cheers


Code:
<HTML>
<HEAD>

<SCRIPT LANGUAGE=&quot;JavaScript&quot; FOR=&quot;btnHello&quot; EVENT=&quot;onclick&quot;>
	alert(&quot;Hello Button&quot;);
</SCRIPT>

<SCRIPT LANGUAGE=&quot;JavaScript&quot; FOR=&quot;Piccie&quot; EVENT=&quot;onfocus&quot;>
	alert(&quot;Hello Piccie&quot;);
</SCRIPT>

</HEAD>
<BODY>
	<img tabIndex=&quot;1&quot; src=&quot;C:\Personal\Graphics\bin.gif&quot; id=&quot;Piccie&quot; title=&quot;Press Alt + B&quot; accessKey=&quot;B&quot;/>
	<button id=&quot;btnHello&quot; title=&quot;Press Alt + h To Activate&quot; accessKey=&quot;H&quot;><U>H</U>ello</button>

</BODY>
</HTML>
 
maybe not that elegant, but efficient :) !
 
OK...A more elegant solution....As with Inputs, the keyboard accelarator fires the onclick event....

Code:
<HTML>
<HEAD>

<SCRIPT LANGUAGE=&quot;JavaScript&quot; FOR=&quot;bin&quot; EVENT=&quot;onclick&quot;>
	alert(&quot;hello&quot;);
</SCRIPT>

</HEAD>
<BODY>

<INPUT ID=&quot;bin&quot; TYPE=&quot;image&quot; SRC=&quot;C:\Personal\Graphics\bin.gif&quot; accessKey=&quot;B&quot;></INPUT>

</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top