Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    New Coder
    Join Date
    Sep 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to open text using a div?

    Hi again,

    First I'll show you the css part my code:

    <style type="text/css">
    <!--
    body {
    margin:50px 0px; padding:0px;
    text-align:center;
    }
    .Content {
    width:675px;
    margin:0px auto;
    text-align:left;
    padding:15px;
    border:1px dashed #333;
    background-color:#eee;
    }
    .ContentB {
    width:auto;
    margin:10px;
    border:1px dashed #333;
    }
    -->
    </style>

    I have a div that calls the class "content". What I would like, and what I don't know if it is possible or not, is if I could open the same info that is in the div with the class "content", in another window containing a div with the class "contentB", by way of clicking a link or button.

    Sorry for not explaining things well. I will try and answer all questions to the best of my ability.

    Thanks for any and or all help that I receive.

  • #2
    New Coder
    Join Date
    Dec 2003
    Location
    California
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can't do that directly with CSS. You'd have to use either Javascript or a combination of Javascript and PHP to achieve that.

    // freak

  • #3
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First off, change your CSS -
    Code:
    #Content {
    ...
    }
    #Content b {
    ...
    }
    Now assign the divs id's of "Content" and "content b" instead of classes.
    This is because these elements are unique within the page; ie, there is only one of each.

    the javascript you would use if they were both on the same page would be something along the lines of
    Code:
    getElementByID(content).innerHTML = getElementByID(content b).innerHTML
    NOTE: I don't claim to know JS, and the above script won't work. I've provided it as an hint in the right direction.

    I take no responsibility for the above nonsense.


    Left Justified

  • #4
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Yeah, you're supposed to have quotes in there ..

    This is a js question so I'll move it to the correct forum and I'm sure someone will be along to help you.
    Omnis mico antequam dominus Spookster!

  • #5
    New Coder
    Join Date
    Sep 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for all of the replies.

    Using Javascript would be fine, but I know nothing about it or at least very little.

    So I can use all the help I can get. I really do appreciate it.

    Thanks again

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    page 1:
    Code:
    <html>
    <head>
    <style type="text/css">
    body {
    margin:50px 0px; padding:0px;
    text-align:center;
    }
    #Content {
    width:675px;
    margin:0px auto;
    text-align:left;
    padding:15px;
    border:1px dashed #333;
    background-color:#eee;
    }
    </style>
    <script type="text/javascript">
    function doOpen(){
      var w = window.open("page2.htm","content2");
      w.focus();
    }
    </script>
    </head>
    <body>
    <form>
    <div id="Content">
    I have a div that calls the class "content". 
    What I would like, and what I don't know if it is possible or not, 
    is if I could open the same info that is in the div with the class "content", 
    in another window containing a div with the class "contentB", by way of clicking a link or button.
    </div>
    <input type="button" value="Open" onclick="doOpen()">
    </form>
    </body>
    </html>
    page2.htm:
    Code:
    <html>
    <head>
    <style type="text/css">
    #ContentB {
    width:auto;
    margin:10px;
    border:1px dashed #333;
    }
    </style>
    <script type="text/javascript">
    function getContent(){
      if (window.opener && !window.opener.closed) 
        document.getElementById('ContentB').innerHTML=window.opener.document.getElementById('Content').innerHTML;
    }
    </script>
    </head>
    <body onload="getContent()">
    <div id="ContentB"></div>
    </body>
    </html>

  • #7
    New Coder
    Join Date
    Sep 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh my gosh,

    A million thanks to glenngv. That is absolutely perfect. Thank you sooooo much.

    Verity

  • #8
    New Coder
    Join Date
    Sep 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have one question. What was given works absolutely perfect! I couldn't have asked for anything better. However, will that only work with an HTML page?

    Can I use that same coding but open a .pl page?

    Would I have to change this bit:
    Code:
    document.getElementById('ContentB').innerHTML=window.opener.document.getElementById('Content').innerHTML;
    So I guess I need to know what part I would need to change so that I could open a .pl page in this same manner.

    Thanks so much,
    Verity

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    What do you exactly mean?
    If you would like to open a perl page (or any server-side language for that matter), then you can just call it in a link or button instead of calling page2.htm.

    <script type="text/javascript">
    function doOpen(){
    var w = window.open("page.pl","content2");
    w.focus();
    }
    </script>
    ...
    <input type="button" value="Open" onclick="doOpen()">

  • #10
    New Coder
    Join Date
    Sep 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm, what you gave me works perfectly as I said before. I tested it using HTML and got the desired result. Then I tried it, so it would open a .pl page and the div didn't resize in the new window.

    Perhaps I missed something, I'll keep at it though.

  • #11
    New Coder
    Join Date
    Sep 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh I see what I don't know how to do. How to add the information contained in page2.htm to .pl code?

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Can you describe your problem again. I was lost when that .pl page came into the picture.

  • #13
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    How to add the information contained in page2.htm to .pl code
    Submit it with a form's element.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #14
    New Coder
    Join Date
    Sep 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by glenngv
    Can you describe your problem again. I was lost when that .pl page came into the picture.
    What you gave me works fine with html. I know html way better than I do Javascript or Perl/cgi. However, I applied your coding to my situation. But it wasn't working properly. Then I realized that, this is because I was missing the page2.htm code. To my understanding the page2.htm code should be the page that opens in the new window and thus probably be included somewhere in my .pl code.

    So the page that I want to open, in my circumstance is a .pl page. I don't know how to add the code in page2.htm to the .pl page coding.

    I swear sometimes I just have to pick the most difficult things to do. LOL

  • #15
    New Coder
    Join Date
    Sep 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Kor
    Submit it with a form's element.
    I hate to sound so dumb when it comes to these things, because I do really know things about designing. However, I know nothing about what you have replied here.

    My knowledge of Javascript and Perl/cgi is non existant to say the least.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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