How to pass textbox name to function in javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Len Elyea
    New Member
    • Dec 2010
    • 1

    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.
    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
  • Logic Ali
    New Member
    • Jul 2010
    • 16

    #2
    Code:
    <input ... onkeyup = "myFunction( this )">
    
    ...
    
    function myFunction( elem )
    {
     alert( elem.name.substring( elem.name.lastIndexOf( '_' ) + 1 ) + '\n\n' + elem.value );
    }

    Comment

    Working...