Advanced Search

Results 1 to 2 of 2

Thread: Passing to a Function

  1. #1
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Passing to a Function

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

    HTML Code:
    <html>
    <head>
    <title></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
    Join Date
    Dec 2004
    Posts
    177
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default

    Well, the way you are doing it:

    Code:
    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;
    }
    Verzeihung!

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
  •