SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing to a Function

    How do I pass an id to a function??
    Or is this even possible.

    HTML Code:
    <html>
    <head>
    <title>
      JavaScript array passing example
    </title>
    <script type="text/javascript">
    
    function init(){
       display(addText1);
       display(addText2);
       display(addText3);
       display(addText4);
    }
    
    function display(var myText){
      var newText = '<h2>' + "Will this change anything..." + '</h2>';
    
       document.getElementById('myText').innerHTML = newText;
    }
    </script>
    </head>
    <body onload="init()">
    
    <div id="addText1"></div>
    <div id="addText2"></div>
    <div id="addText3"></div>
    <div id="addText4"></div>
    </body>
    </html>

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I pass an id to a function??
    You can pass the id value as a string to a function.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Location
    South Africa
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    q_X_p

    <html>
    <head>
    <title>
    JavaScript array passing example
    </title>
    <script type="text/javascript">

    function init(){
    display('addText1');
    display('addText2');
    display('addText3');
    display('addText4');
    }

    function display(myText){
    var newText = '<h2>Will this change anything...</h2>';

    document.getElementById(myText).innerHTML = newText;
    }
    </script>
    </head>
    <body onload="init()">

    <div id="addText1"></div>
    <div id="addText2"></div>
    <div id="addText3"></div>
    <div id="addText4"></div>
    </body>
    </html>


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
  •