Welcome to WebmasterWorld Guest from 54.167.46.29

Forum Moderators: open

Message Too Old, No Replies

Use cookie to trigger innerHTML change

if(isset($_COOKIE[cookiename])) used to check

     
9:45 am on Mar 13, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 23, 2008
posts:72
votes: 0


Using this code, the innerHTML isn't changing. How do I make the innerHTML change? Maybe use setTimeout?

Code:

<?php
if(isset($_COOKIE['pollchoice']))
echo "<script type='text/javascript' language='javascript'>document.getElementById('pollarea').innerHTML=\"poll results here\"</script>";
?>

Any ideas? I'm sure this is much easier than I'm making it :P

1:44 pm on Mar 13, 2008 (gmt 0)

Moderator from CA 

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4059
votes: 0


The javascript looks syntactically correct.
try this quick test:

<?php print($_COOKIE['pollchoice']); ?>

2:48 pm on Mar 13, 2008 (gmt 0)

Full Member

5+ Year Member

joined:Dec 3, 2006
posts:257
votes: 0


Why do you write javascript code from php?
You should either test the cookie in js, or write #pollarea's content directly in php. There is no use for js here.
8:30 pm on Mar 13, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 23, 2008
posts:72
votes: 0


Okay, I got it working.

@Achernar, not sure quite what you mean....could you please explain more?

1:32 am on Mar 14, 2008 (gmt 0)

Full Member

5+ Year Member

joined:Dec 3, 2006
posts:257
votes: 0


Since you're testing the cookie in php, why are echoing javascript that write html ?

It would be simpler to write directly:

<div id="pollchoice"><?php
if (isset($_COOKIE['pollchoice'])) echo "poll results here";
?></div>

or, if you don't need the empty div:

<?php
if (isset($_COOKIE['pollchoice'])) echo "<div id=\"pollchoice\">poll results here</div>";
?>
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members