SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member chriswick's Avatar
    Join Date
    Nov 2006
    0 Post(s)
    0 Thread(s)

    Trying to get javascript variable values to pass into an external .js file?

    I am trying to make a widget for the website I'm building. I want it so when people change the color for the background it changes when the file is inported out of the .js file.

    Example Code: (This is what I want to get working)

    HTML Code:
    <SCRIPT language="JavaScript">
    bg_color = "#FFFFFF";
    <SCRIPT TYPE="text/javascript" SRC=""></SCRIPT>
    Now all I need is the codes that go into the Javascript file itself I made this but it does not work.

    This is what is not working to make the other code work.

    HTML Code:
    function stamp(bg_color) {
    document.write("<body bgcolor= "+ bg_color + ", ");
    Any help would be great!


  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    3 Post(s)
    0 Thread(s)
    <script type='text/javascript'>
    var bg_color = '#ffffff'
    <script type='text/javascript' src=''></script>

    function stamp() {
    document.write("<body bgcolor= "+ bg_color + ", ");

    I believe by passing bg_color as a parameter, bg_color inside the function is considered local, by declaring bg_color outside originally, it is global and can be accessed by any javascript function on the page. So you do not need to pass it as a parameter, unless the code that invoked the stamp() took the global variable and modified it, before passing it to stamp - which I'm assuming u didn't do.


Posting Permissions

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