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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Location
    N Michigan
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    How to pass textbox name to function in javascript

    I have a php script which dynamically creates a table containing text boxes with variable names. Example:
    Code:
    echo '<td align="center" bgcolor="'.$bgcolor.'"><input type="text" name="payable_'.$key.'" id="payable_'.$key.'" value="'.$payable.'" size="3" maxlength="4" /></td> ';

    In the above instance the text box name might be 'payable_23323'.

    I need to code an onKeyUp event which sends the text box name to a function, and in that function I need to retrieve the text box name and the string after 'payable_' together with the value the user has input into the text box.

    Any help is greatly appreciated . . . I have been Googling this for hours to no avail - probably because I don't know what to search for . . .

    Thanks

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    <input ... onkeyup="whatever(this);"/>

    and then the function can do:

    Code:
    function whatever( fld )
    {
        var name = fld.name;
        var value = fld.value; 
        var key = name.substring(8); // everything after "payable_"
        alert("The field " + name + " has the value " + value + " and the key " + key);
        // or whatever else you want to do with them
    }
    Read up on the use of this -- it's a really powerful little keyword.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    lelyea (12-27-2010)

  • #3
    New to the CF scene
    Join Date
    Nov 2007
    Location
    N Michigan
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    This solution is exactly what I needed. Thank you for your expert help!!


  •  

    Posting Permissions

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