SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2002
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing variables

    here is my code:
    PHP Code:
    <script language=javascript>
    function 
    switchTemplate(templatename) {
    template.value=document.theform.name.value;
    }
    </script> 
    The script seems to be looking for a field actually named "name" rather than picking up the content of the variable "name".

    How do I fix this?

    Thanks in advance,
    David

  2. #2
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script language=javascript>  function switchTemplate(template, name) {  template.value=document.theform.name.value;  }  </script>
    A good piece of advice: Don't name your variables the same thing as JS objects. It will always recognize that as the looking for the name of a specific form. try this instead:

    Code:
    <script language=javascript>
    function switchTemplate(template, myName) {
    template.value=document.theform.myName.value;
    }
    </script>
    That should do the trick

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  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)
    Or, don't use the exposed properties and use the collections instead

    document.forms['theform'].elements['name'].value
    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
  •