SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot j3ph's Avatar
    Join Date
    Jan 2006
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to append button value to end of text box when button is pressed

    I'm not afraid to admit that I am absolutely helpless when it comes to JavaScript. I can't for the life of me write even the simplest of scripts on my own.

    What I'm trying to do is replicate the iPhone's keypad screen. So when someone clicks on the number 1 button, a 1 is appended to the input box above. I have it working in jQuery, but the tablet that is displaying the page is slow to react to each button press. I was hoping if I could have the same functionality without having to load jQuery it may speed things up a bit.

    Thanks

  2. #2
    SitePoint Zealot j3ph's Avatar
    Join Date
    Jan 2006
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind. Please disregard. As soon as I posted this I continued to Google this topic and found exactly what I needed.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,715
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    If you had a number field and a button called "three"

    Code html4strict:
    <input id="numbers" type="text">
    ...
    <button id="three">3</button>

    You can attach an onclick event to the button, which would update the number input.

    Code javascript:
    function addContentToNumbers() {
        document.getElementById('number').value += this.innerHTML;
    }
     
    var button = document.getElementById('three');
    button.onclick = addContentToNumbers;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •