SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2001
    Location
    Sussex, WI
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function parameter question

    Hi;

    I'm kind of a "JavaScript Novice", so pardon my ignorance

    I'm trying to create a function that has a single parameter which is supposed to be the name of an object on a form. For example, if I have a textbox named "txtBox", that's the value I want to send to the function as a parameter:

    <INPUT TYPE="text" NAME="txtBox" VALUE="WhoDat!">

    However, since the name would be passed to the function as a string, how to I define that string as a textbox name, and not a string so I can use the textboxes properties? For example, the following script returns an error:

    <SELECT NAME="selEmployeeName" onChange="fncDupeValue('txtBox');">

    <SCRIPT language="JavaScript">
    function fncDupeValue(txtBox)
    {
    var strValue = document.forms[0].txtBox.value;
    return document.forms[0].txtBox2.value = strValue;
    }

    </SCRIPT>

    All I'm attempting to do here is send the name of the textbox into the function as a parameter so I can identify that textbox in the function, retrieve it's value, and set another textbox's value to be the same.

    How do I do this?
    Sincerely,
    Todd M. Taylor

  2. #2
    SitePoint Member
    Join Date
    Aug 2001
    Location
    Sussex, WI
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alrighty, I figured it out...

    document.all("whatever")

    Thanks, Me
    Sincerely,
    Todd M. Taylor

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Better way

    function fncDupeValue( f, fromElem, toElem )
    {
    f.elements[toElem].value = f.elements[fromElem].value;
    }
    </SCRIPT>

    <SELECT NAME="selEmployeeName" onChange="fncDupeValue(this.form, 'txtBox','txtBox2');">
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

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