#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2014
    Posts
    34
    Rep Power
    4

    Multiple actions in a Javascript comand


    Hi All,

    I've written the javascript below to be executed on a button click, but it seems when I click on the button it doesn't do anything. Can anyone suggest as to why this may be?

    Code:
    <button onclick="ClientJS()">Client JS</button>
    <p id="client"></p>
    <script>
    function ClientJS() {    
        onclick='parent.frame_c.href="phplist1.php"';
        onclick='parent.frame_d.href="blankgreen.html"';
        onclick='parent.frame_e.href="blank.html"';
        onclick='parent.frame_f.href="blank.html"';
    }
    </script>
    Many Thanks
    Graham
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    Code:
    onclick='parent.frame_c.href="phplist1.php"';
    All you're doing is creating a variable named "onclick" whose value is the contents of that string. (Then you overwrite it three times with three different values.)

    So you know that onclick can be used to execute code when the thing is clicked. Great. And you're using that to execute ClientJS(). So whatever code you put in ClientJS will execute when the thing is clicked, right?

    So...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2014
    Posts
    34
    Rep Power
    4
    OK, So I amended my code to the below:

    Code:
    <button onclick="ClientJS()">Client JS</button>
    <p id="client"></p>
    <script>
    function ClientJS() {
        parent.frame_c.href="phplist1.php";
        parent.frame_d.href="blankgreen.html";
        parent.frame_e.href="blank.html";
        parent.frame_f.href="blank.html";
    }
    
    
    </script>
    Hoping I was heading in the right direction, But still getting no reaction when I click the button, Am I on the right track?

    Many Thanks,
    Graham
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2014
    Posts
    34
    Rep Power
    4
    I've also just tried
    Code:
    parent.frame_c.assign("phplist1.php");
    and that doesn't seem to work either
  8. #5
  9. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    Using "parent.frame_c", or the full form window.parent.frames["frame_c"], gets you an object - a window - that represents the frame as it works in the browser. It is not the actual <frame> from the HTML.

    That means if you want to change the location then you need its .location property.
    Code:
    parent.frame_c.location.assign("phplist1.php");
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2014
    Posts
    34
    Rep Power
    4
    Many Thanks for the assistance,

    I have developed it on to this:

    Code:
    <button onclick="ClientJS()">Client JS</button>
    <p id="client"></p>
    <script type="text/javascript">
    function ClientJS() {
        Frame_C();
        Frame_D();
        Frame_E();
        Frame_F();
    }
    function Frame_C() {
        parent.frame_c.location.assign("phplist1.php");
    }
    
    function Frame_D() {
        parent.frame_d.location.assing("blankgreen.html");
    }
    
    function Frame_E() {
        parent.frame_e.location.assign("blank.html");
    }
    
    function Frame_F() {
        parent.frame_f.location.assign("blank.html");
    }
    
    </script>
    However it seems whatever I try only the first line / command of the batch is executing and it's frame content is changing. Any assistance would be greatly appreciated.

    Many Thanks,
    Graham
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2014
    Posts
    34
    Rep Power
    4
    Nailed it!!

    I don't know why, but it seems to work now!!

    Code:
    <button onclick="ClientJS()">Client JS</button>
    <p id="client"></p>
    <script type="text/javascript">
    function ClientJS() {
        Frame_C();
        Frame_D();
        Frame_E();
        Frame_F();
    }
    function Frame_C() {
        onclick='parent.frame_c.href="phplist1.php"';
        parent.frame_c.location.assign("phplist1.php");
    }
    
    function Frame_D() {
        onclick='parent.frame_d.href="blankgreen.html"';
        parent.frame_d.location.assign("blankgreen.html");
    }
    
    function Frame_E() {
        onclick='parent.frame_e.href="blank.html"';
        parent.frame_e.location.assign("blank.html");
    }
    
    function Frame_F() {
        onclick='parent.frame_f.href="blank.html"';
        parent.frame_f.location.assign("blank.html");
    }
    
    </script>
    Many Thanks,
    Graham
  14. #8
  15. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    Well, if you're executing this from with the C frame then that wouldn't surprise me. In fact running this from any of the four frames isn't good.

    I'd create a Javascript function in the parent page (with the frameset) that allows the child frames to change the locations.
    Code:
    function AssignFrames(C, D, E, F) {
    	window.frame_c.location.assign(C);
    	window.frame_d.location.assign(D);
    	window.frame_e.location.assign(E);
    	window.frame_f.location.assign(F);
    }
    then in the child page
    Code:
    parent.AssignFrames("phplist1.php", "blankgreen.html", "blank.html", "blank.html");

IMN logo majestic logo threadwatch logo seochat tools logo