...

View Full Version : Replacing div content based on variable value



Staggan
08-21-2010, 11:51 AM
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

abduraooft
08-21-2010, 12:05 PM
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?

Staggan
08-21-2010, 12:50 PM
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?

gizmo1650
08-21-2010, 01:16 PM
give the sub-dive an id, or use the childNodes property of the div

Staggan
08-21-2010, 04:29 PM
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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum