#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Posts
    12
    Rep Power
    0

    javascript changing other frames background color


    can anyone help please

    i have 4 frames on my page. in one of my frames i have designed a background modificator you select a color from the selection list and when the button to change color is clicked it changes to the selected color. What im now trying to do is add an extra option in where the user can select which frame to change the background too. this is where ive come to a problem does anyone have a solution ?

    many thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Posts
    1,882
    Rep Power
    20
    To change the current page
    Code:
    <p><a href="javascript:" onclick="document.body.bgColor='red'">Change This Frame</a></p>

    To change a frame you have to reference the frame name
    Code:
    <p><a href="javascript:" onclick="parent.mainFrame.document.body.bgColor='blue'">Change That Frame --&gt;</a></p>
  4. #3
  5. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    <form>
    Change
    <select name="frame">
    <option value="self">This</option>
    <option value="left">Left</option>
    <option value="right">Right</option>
    <option value="bottom">Bottom</option>
    </select> frame to
    <select name="colors">
    <option value="tan">Tan</option>
    <option value="olive">Olive</option>
    <option value="coral">Coral</option>
    <option value="peru">Peru</option>
    <option value="orange">Orange</option>
    </select> background
    <input type="button" value="now" onclick="docolor(frame,colors)">
    </form>

    function docolor(frame_sel, color_sel) {
    var frame = frame_sel.options[frame_sel.selectedIndex].value;
    var color = color_sel.options[color_sel.selectedIndex].value;
    var obj = (frame == 'self') ? window : top;
    obj[frame].document.body.style.background = color;
    }

    This assumes frames named 'left', 'right', 'bottom', and the one the code is written into. Untested.

IMN logo majestic logo threadwatch logo seochat tools logo