Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Command Button & Functions

    I wish to switch the onclick event of a Command Button between Functions based upon the onfocus event of a text Field. For example, I shall use the onclick event of one Button to fill in data in many Text Fields as I tab from field to field. How would I code this?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I read your post several times but I didn't get what you really wanted. Can you explain again?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you want a button's onClick event to change based on where its focus is? I didn't understand everything after "for example" though..

  • #4
    New Coder
    Join Date
    Oct 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Clarification

    I apologize for the initial ambiguity. I hope this is more concise. My form has four Text Fields and one Command Button. I wish to click on the Command Button and have it pass its Value to whichever Text Field has the Focus. How do I code this?

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    var currentField;
    function setCurrentField(val){
      if (currentField) currentField.value = val;
    }
    ...
    <input type="button" name="Set" onclick="setCurrentField('hello!')" />
    <input type="text" name="txt1" onfocus="currentField=this" />
    <input type="text" name="txt2" onfocus="currentField=this" />
    <input type="text" name="txt3" onfocus="currentField=this" />
    <input type="text" name="txt4" onfocus="currentField=this" />
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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