SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing string to function

    Hello,
    I am trying to pass a string to a function but the code keeps coming back with an error.
    I cant seem to locate what im doing wronge, please help.
    Thanks.

    here is the code:

    Code:
    <body>
    <script type="text/javascript">
    
    function f(a,b)
    {
    	document.body.bgColor=' " ' + a + ' " '
    	document.getElementById("d").style.color=' " ' + b + ' " '
    }
    
    </script>
    
    <button onclick="f('black','white')">
    Change the text and bgcolor
    </button>
    
    <p id="d">Example</p>
    
    </body>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,700
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    =' " ' + a + ' " ' should be just = a
    And likewise for b
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh cool, that works
    thanks alot!


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
  •