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.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2010
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replacing div content based on variable value

    I have a piece of javascript I am trying to get working....


    Original Div container

    <div id="Step5">
    <div class="emptysegment segseparator" style="width:139px;">
    <div class="barsteptext"><strong>5.</strong> Post content faster</div>
    <div class="barstepimg"><img src="http://XXXXX/my_dir/images/XXXX/fb_buttons/publish_permission.gif" onclick="onPublishPermissionPressed();"/></div>
    </div>

    Now, depending on the value of $isfan I want to change the content of div Step5

    So I do this...


    Set $isfan = 1 to test....


    <script type="text/javascript"><!--
    $isfan = 1;
    </script>


    <script type="text/javascript"><!--
    function ReplaceContentInContainer(id,content) {
    var container = document.getElementById(id);
    container.innerHTML = content;
    }
    </script>


    <script type="text/javascript">

    if ($isfan = 1){

    var content = '<div class="fullsegment" style="width:139px;">
    <div class="barsteptext"><strong>5.</strong> Post content faster</div>
    <div class="barstepcomplete"></div>
    </div>';

    ReplaceContentInContainer('Step5',content);
    }

    </script>


    Essentially I want to replace the contents of div container Step5 with new content based on the value of $isfan.... but I get an error when I try this.... object doesn’t support this method or property...

    Any ideas?

    Thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Now, depending on the value of $isfan I want to change the content of div Step5
    What's that? From where you get that value?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Aug 2010
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OOps

    I was assigning the value 1 to the $isfan, instead of comparing.. this now works..

    However, when I put this in my main page it does not... the only difference being the div I want to replace is an element of another div...

    Thoughts?

  • #4
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    give the sub-dive an id, or use the childNodes property of the div

  • #5
    New Coder
    Join Date
    Aug 2010
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the comments..

    The code bleow now works as expected.. however, if I include this page within another page, the ReplaceContentInContainer function does not seem to work....

    Is it because the reference to the div changes as it is running from an included page instead of a standalone?




    <!-- ORIGINAL DIV -->

    <div id="Step5">
    <div class="emptysegment segseparator" style="width:139px;">
    <div class="barsteptext"><strong>5.</strong> Post content faster</div>
    <div class="barstepimg"><img src="http://XXXXX/my_dir/images/XXXX/fb_buttons/publish_permission.gif" onclick="onPublishPermissionPressed();"/></div>
    </div>


    <!-- DIV REPLACEMENT FUNCTION -->

    <script type="text/javascript"><!--
    function ReplaceContentInContainer(id,content) {
    var container = document.getElementById(id);
    container.innerHTML = content;
    }
    </script>

    <!-- SEND NEW DIV -->

    <script ="text/javascript">
    var content = '<div class="fullsegment" style="width:139px;"><div class="barsteptext"><strong>5.</strong> Post content faster</div><div class="barstepcomplete"></div></div>';

    ReplaceContentInContainer('Step5',content);
    }
    </script>


  •  

    Posting Permissions

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