antonyfal Posted September 20, 2011 Share Posted September 20, 2011 Hi, I had this little script setup before and it worked like a charm, even posted in this forum for others. I am now trying to apply it somewhere else on my site and it doesn't work now!?. What happens is i load a cookie with X name and then this will detect the cookie and load the one div and close the other div, if no cookie then the opposite happens.. Below: if the cookie exists then the div id="registerd" should be display block, and unregistered should be display none.. Im getting no display at all and when i check, the cookie is set. //to note: maybe it makes a diiference, but the file placing the cookie is in another folder on the server? IE: folder/folder/folder/folder and the file looking for the cookie is in folder2/folder2/folder/folder2... Just for example.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><appmail:object name="pagetitle" /></title> <appmail:include file="/includes/links.html" /> <script type="text/javascript"> function checkregCookie() { registeredDiv=document.getElementById("registered"); unregisteredDiv=document.getElementById("unregistered"); if (document.cookie.indexOf("todaysfiles")!=-1) { registeredDiv.style.display="block"; unregisteredDiv.style.display="none"; } else { registeredDiv.style.display="none"; unregisteredDiv.style.display="block"; } } </script> </head> <body> <!-- Here's the "registered" DIV element It doesn't display until the cookie is set --> <div id="registered" style="display:none"> <div id="taskbar"></div> <img src="/images/appmail_logo.png" border="0" alt="<appmail:object name='productname' />" hspace="10" /> <appmail:object name="message" id="message" /> <div id="login-form"> <div class="boxtitle"><appmail:label name="register.sign_up" /></div> <div class="boxcontent"> <form name="registerform" action="./?_action=register" method="post"> <input type="hidden" name="_user" value="" /> <input type="hidden" name="_action" value="login" /> <input type="hidden" id="rcmlogintz" name="_timezone" value="_default_" /> <input type="hidden" name="_url" value="_task=mail" /> <input type="hidden" name="_host" value="<appmail:var name="config:default_host" />" /> <input type="hidden" name="_login_lang" value="<appmail:var name="session:language" />" /> <table> <appmail:object name="domaingroups" /> <tr> <td align="right" class="title"><appmail:label name='register.email' /> <input size="15" class="focus" name="_username" autocomplete="off" type="text" value="<appmail:var name='request:_username' />"><span> @</span></td> <td> <appmail:object name="domainselector" /> </td> </tr> <tr> <td class="title" nowrap><appmail:label name='register.password' /></td> <td nowrap> <input name="_pass" type="password"> </td> </tr> <tr> <td class="title" nowrap><appmail:label name='register.confirm_password' /></td> <td nowrap> <input name="_confirm_pass" type="password"> </td> </tr> </table> <p style="text-align:center;"><appmail:button command="plugin.register-save" id="register_submit" type="input" class="button mainaction" label="register.sign_up" /> <span> </span> <input onclick="document.location.href='./'" type="button" class="button" value="<appmail:label name='register.back' />" /></p> </form> </div> </div> <div> <!-- Here's the "unregistered" DIV element --> <div id="unregistered" style="display:none; text-align:center;"> <font color="#ff0033"><b>You do not have permission to access this Area.<br>Please Login and try again.<b></font> </div> <script type="text/javascript"> //check for the cookie and display DIV checkregCookie(); </script> <script type="text/javascript"> var d = new Date(); document.getElementById("rcmlogintz").value = (d.getTimezoneOffset() / 60) * -1; </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/247498-cookies-detect-then-open-one-div-and-close-the-other-not-working/ Share on other sites More sharing options...
antonyfal Posted September 21, 2011 Author Share Posted September 21, 2011 i just put an edited version here, maybe it would be easier to read: i place the cookie with this code: <script type="text/javascript"> document.cookie ="todaysfiles=1"; </script> both pages are .html files // here is page that looks for cookie <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><appmail:object name="pagetitle" /></title> <appmail:include file="/includes/links.html" /> <script type="text/javascript"> // here is the cookie check funtion function checkregCookie() { registeredDiv=document.getElementById("registered"); unregisteredDiv=document.getElementById("unregistered"); if (document.cookie.indexOf("todaysfiles")!=-1) { registeredDiv.style.display="block"; unregisteredDiv.style.display="none"; } else { registeredDiv.style.display="none"; unregisteredDiv.style.display="block"; } } </script> //cookie check funtion ends here </head> <body> <!-- Here's the "registered" DIV element // start of registered div object It doesn't display until the cookie is set --> <div id="registered" style="display:none"> <div id="taskbar"></div> <img src="/images/appmail_logo.png" border="0" alt="<appmail:object name='productname' />" hspace="10" /> <appmail:object name="message" id="message" /> <div id="login-form"> <div class="boxtitle"><appmail:label name="register.sign_up" /></div> <div class="boxcontent"> <form name="registerform" action="./?_action=register" method="post"> <input type="hidden" name="_user" value="" /> <input type="hidden" name="_action" value="login" /> <input type="hidden" id="rcmlogintz" name="_timezone" value="_default_" /> <input type="hidden" name="_url" value="_task=mail" /> <input type="hidden" name="_host" value="<appmail:var name="config:default_host" />" /> <input type="hidden" name="_login_lang" value="<appmail:var name="session:language" />" /> <table> <appmail:object name="domaingroups" /> <tr> <td align="right" class="title"><appmail:label name='register.email' /> <input size="15" class="focus" name="_username" autocomplete="off" type="text" value="<appmail:var name='request:_username' />"><span> @</span></td> <td> <appmail:object name="domainselector" /> </td> </tr> <tr> <td class="title" nowrap><appmail:label name='register.password' /></td> <td nowrap> <input name="_pass" type="password"> </td> </tr> <tr> <td class="title" nowrap><appmail:label name='register.confirm_password' /></td> <td nowrap> <input name="_confirm_pass" type="password"> </td> </tr> </table> <p style="text-align:center;"><appmail:button command="plugin.register-save" id="register_submit" type="input" class="button mainaction" label="register.sign_up" /> <span> </span> <input onclick="document.location.href='./'" type="button" class="button" value="<appmail:label name='register.back' />" /></p> </form> </div> </div> <div> // end of registered div object <!-- Here's the "unregistered" DIV element --> // here is start of unregistered div object <div id="unregistered" style="display:none; text-align:center;"> <font color="#ff0033"><b>You do not have permission to access this Area.<br>Please Login and try again.<b></font> </div> <script type="text/javascript"> //check for the cookie and display DIV checkregCookie(); </script> // unregistered div object ends here <script type="text/javascript"> var d = new Date(); document.getElementById("rcmlogintz").value = (d.getTimezoneOffset() / 60) * -1; </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/247498-cookies-detect-then-open-one-div-and-close-the-other-not-working/#findComment-1271315 Share on other sites More sharing options...
Pikachu2000 Posted September 21, 2011 Share Posted September 21, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/247498-cookies-detect-then-open-one-div-and-close-the-other-not-working/#findComment-1271502 Share on other sites More sharing options...
antonyfal Posted September 21, 2011 Author Share Posted September 21, 2011 thanks for that: i tried the in the first attempt and my last one i tried . Can you take a crack at solving this one for me? do you have any ideas why the cookie function is not working? is it because the files are in folder's apart? or maybe because they are in different apps? please i need to get this working.. im still battling with it. best regards antony Quote Link to comment https://forums.phpfreaks.com/topic/247498-cookies-detect-then-open-one-div-and-close-the-other-not-working/#findComment-1271516 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.