www.webdeveloper.com
Results 1 to 8 of 8

Thread: Stuck for days....can't change styleSheets through Java script

  1. #1
    Join Date
    Nov 2009
    Posts
    13

    Stuck for days....can't change styleSheets through Java script

    Hi All

    I've been stuck literally for 24 hours or more trying to figure out how to change a styleSheet attribute inside a Java function, instead of calling it using 'href".
    Basically what I'm doing is using PHP OpenChat and I'm just wanting to change the background room picture when going from one "room" to another, by clicking an html tag: "SHOW ROOM 4 PICTURE". There are 4 different rooms, each a different stylesheet (1-4).



    The function works well enough executed inside the template (.tpl) file:

    <a href="javascript:document.styleSheets[0].disabled=true;
    document.styleSheets[1].disabled=true;
    document.styleSheets[2].disabled=true;
    document.styleSheets[3].disabled=false;
    parent.refreshcssscreen_routine();
    ">SHOW ROOM 4 PICTURE</a>


    However, when I try to call it as a subroutine from within a javascript file:

    <a href="javascriptarent.ChangeRooms();
    ">SHOW ROOM 4 PICTURE</a>


    and In the Java subroutine file......:

    (within js file)
    function ChangeRooms()
    {
    document.styleSheets[0].disabled=true;
    document.styleSheets[1].disabled=true;
    document.styleSheets[2].disabled=true;
    document.styleSheets[3].disabled=false;

    };


    No go.
    How do you refer to the element "styleSheets[1]" for instance, inside the JavaScript file?
    This is only one possible example I've tried, I've tried every combination of 'getElementById', 'getElementsByName', etc, etc, etc.
    No matter what combination I try won't work at all. I've poured over reams of Google articles. Nothing works.

    Has anyone any ideas? I am no Java expert but this has been a needle in a haystack search for me.
    Thanks for any ideas.....

  2. #2
    Join Date
    Oct 2006
    Posts
    939
    You left out parent.refreshcssscreen_routine(); in your js function?

  3. #3
    Join Date
    Nov 2009
    Posts
    13

    Question

    I have a screen refresh routine, but I was using this one....separately.
    That one DOES work, and I can call it in the Java script from the tpl:

    function Refresh()
    {
    var i, a, s;
    a = document.getElementsByTagName('link');
    for (i = 0; i < a.length; i++) {
    s = a[i];
    if (s.rel.toLowerCase().indexOf('stylesheet') >= 0 && s.href) {
    var h = s.href.replace(/(&|%5C?)forceReload=\d+/, '');
    s.href = h + (h.indexOf('?') >= 0 ? '&': '?') + 'forceReload=' + (new Date().valueOf())
    }
    }
    };


    Does this mean what I posted may be correct otherwise? I'm groping in the dark..............

  4. #4
    Join Date
    Nov 2009
    Posts
    13
    Here's what I did in the tpl, for ROOM 3.


    <a href="javascript:document.styleSheets[0].disabled=true;
    document.styleSheets[1].disabled=true;
    document.styleSheets[2].disabled=false;
    document.styleSheets[3].disabled=true;
    parent.Refresh(); /* call refresh subroutine, this works */
    ">SHOW ROOM THREE PICTURE</a>
    &nbsp;&nbsp;




    That works. But I don't want to do this in the tpl called from an href statement like this manually for each room. There has to be some way I can call it as a subroutine in the JavaScript file.
    I need to figure out how to do that, because eventually I'm going to call the room background change in an "ONCHANGE" statement. There is a drop-down box which lists the rooms, and so then I can put the all to the function in there and when the user navigates around different rooms, they will see different pictures.
    I'm doing this in baby-steps, crawling slowly across the broken glass..........lol


    ((eventually will call it from this routine, instead of clicking an html link)))

    <select title="<?=$_SESSION['translator']->out('CHOOSE_CHANNEL')?>" class="selectbox" name="channel" onchange="parent.ChangeRooms(.......);parent.setChannel(this);checkChannel(this);formPost=1;submit() ;">


    So far, I'm defeated............

  5. #5
    Join Date
    Nov 2009
    Posts
    13

    Arrow

    Here's the style sheets (earlier in the tpl):

    <title>###TITLE###</title>
    <link rel="stylesheet" id="outsheet" href="@@@THEME_PATH@@@/css/output1.css"/>
    <link rel="stylesheet" id="outsheet" href="@@@THEME_PATH@@@/css/output2.css"/>
    <link rel="stylesheet" id="outsheet" href="@@@THEME_PATH@@@/css/output3.css"/>
    <link rel="stylesheet" id="outsheet" href="@@@THEME_PATH@@@/css/output4.css"/>


    So there's 4 css files, each one with a different room picture.
    So eventually, you click the drop-down box, change rooms, and the room picture changes.

  6. #6
    Join Date
    Nov 2009
    Posts
    13
    hellllllllllllllllllllllllllllllllllp........................

  7. #7
    Join Date
    Nov 2009
    Posts
    13

  8. #8
    Join Date
    Oct 2006
    Posts
    939
    Oh, I see. That's a Java applet. Did you look for a java forum? Javascript might not be the answer for the problem.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles