homepage Welcome to WebmasterWorld Guest from 54.197.215.146
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Use cookie to trigger innerHTML change
if(isset($_COOKIE[cookiename])) used to check
Br3nn4n




msg:3599363
 9:45 am on Mar 13, 2008 (gmt 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

 

httpwebwitch




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

The javascript looks syntactically correct.
try this quick test:

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

Achernar




msg:3599576
 2:48 pm on Mar 13, 2008 (gmt 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.

Br3nn4n




msg:3599915
 8:30 pm on Mar 13, 2008 (gmt 0)

Okay, I got it working.

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

Achernar




msg:3600125
 1:32 am on Mar 14, 2008 (gmt 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>";
?>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved