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
    Regular Coder
    Join Date
    Apr 2006
    Posts
    311
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Pass Id to function from event handler?

    How MAY I pass the Id of textfield_X to function_Y from an event handler (onChange?) in dropdown_Z?

    Ex:

    //function_Y
    function populateTextField(obj){
    document.getElementById("ANYTextfield").value=obj;
    }

    //textField_X
    <input type="text" name="ThisTextfield" id="ThisTextfield">


    dropDown_Z
    <select name="dropdownZ" onChange="populateTextField(this.value;">
    <option value="01">Option 1</option>
    <option value="02">Option 2</option>
    </select>

    I was thinking I might name the dropdown the same as the Textfield Id, but not sure how to pass that parameter to the function.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Add another variable to the function_y.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function populateTextField(what,obj)
    {
    document.getElementById(what).value=obj;
    }
    </script>
    </head>
    
    <body>
    <form action="#" method="post">
    <input type="text" name="ThisTextfield" id="ThisTextfield">
    <select name="dropdownZ" onchange="populateTextField('ThisTextfield',this.value);">
    <option value="01">Option 1</option>
    <option value="02">Option 2</option>
    </select>
    </form>
    </body>
    </html>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Apr 2006
    Posts
    311
    Thanks
    17
    Thanked 0 Times in 0 Posts
    WOW THAT WAS FAST!

    There's nothing more aggravating than asking a simple question and getting unnecessarily complicated answers! I've an operation which calls for a tweezers but have been getting answers recommending backhoes and bulldozers.

    THANK YOU!!!
    Last edited by fuzzy1; 04-11-2006 at 03:25 PM.


  •  

    Posting Permissions

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