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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onclick: multiple textfields

    I found a simple script which inserts a character in a given text field:

    <script type="text/javascript">
    function insert(el,ins) {
    if (el.setSelectionRange){
    el.value = el.value.substring(0,el.selectionStart) + ins + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length);
    }
    else if (document.selection && document.selection.createRange) {
    el.focus();
    var range = document.selection.createRange();
    range.text = ins + range.text;
    }
    }
    </script>

    <form name="f">
    <input type="button" value="a" onclick="insert(this.form.ta,'a')">
    <input type="text" name="ta" />
    </form>
    If I add another field, the script continues to insert in the text field labeled as "ta". Is it possible to change the script so that the character would be inserted where the cursor is and regardless the text field name.

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How about checking if the text area is in onfocus or onblur?


  •  

    Posting Permissions

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