SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    last button pressed "focus"

    I am doing an onscreen keyboard form (don't ask), and as such I was trying to create a generic "letter" button.
    The idea is to create the buttons with the letter as the id, the onclick event would (in the simplest sense) loop through the form object and find the button with the last focus. The ID would then be inserted into a textarea. For the life of me I cannot seem to find a focus property, I can find the onFocus method, but that's not what I'm after :-)
    My simple code is below

    keyboard.html

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Javascript Keyboard</title>
        <script type="text/javascript" src="javascript/keyboard.js"></script>
    </head>
    <body>
    <form name="keyPresses" action="">
        <textarea name="textBoxThing"  cols="80" rows="2" ></textarea>
        <input type="button" value="a" name="a" onclick="keyPressed(this.form.textBoxThing)" /> &nbsp;
        <input type="button" value="b" name="b" onclick="keyPressed(this.form.textBoxThing)" />&nbsp;
        <input type="button" value="del" name="del"  onclick="keyPressed(this.form.textBoxThing)" />&nbsp;
        <input type="button" value="cls" name="cls" onclick="keyPressed(this.form.textBoxThing)" />&nbsp;
    </form>
    </body>
    </html>
    keyboard.js
    Code:
    function keyPressed(inputBoxObj)
    {
        for (var i = 0; i < document.keyPresses.length; i++) {
            if (document.keyPresses[i].blur)
    	    {
    	        alert(document.keyPresses[i].type);
    	    }
    	}   
    	return false;
    }
    I started Javascript today.

    Thanks in advance.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    Hi clockwork, welcome to the forums,
    I started writing javascript a few years ago, got away from it to learn other things, and have just recently begun to look at it again. I would have bet that there was a focus property, but now realise there isn't! It probably would be better to use an event handler for click in your project.

  3. #3
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm off home now, so unless any-one disagrees with you Mittineaque I shall have to do it the Loooonnnnggg way...

    Thanks anyway.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •