473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Div not working.

Howdy All,

I am trying to detect if the user has cookies enabled on a page and
display text accordingly. My cookie detection works but I can't get
the divs to work. Here is the javascript and html does anybody have
any sugestions?

<script language="JavaScript">
function window_onload() {
var sCookie;

SetCookie("CookieTest","True");
sCookie = GetCookie("CookieTest");

if (sCookie = "True")
{
divNoCookies.style.display = "none";
divDisclaimer.style.display = "block";
}

}

window.onload = window_onload;
</script>
<div ID="divDisclaimer" Name="divDisclaimer" style="display:none">
<!-- #include file='County\Disclaimer.htm' -->
</div>
<div ID="divNoCookies" Name="divNoCookies" style="display:block">
<tr>
<td>
<FONT color=red>
Your browser or your firewall is not set up to allow
cookies. This site requires session cookies. Please check your
browser
settings or contact your system administrator.
</FONT>
</td>
</tr>
</div>

Jul 23 '05 #1
2 1590
On 28/03/2005 17:48, DBLWizard wrote:
<script language="JavaScript">
The language attribute has been deprecated for a very long time. Use
the (required) type attribute instead:

<script type="text/javascript">
function window_onload() {
Rather than introducing a global identifier unnecessarily, assign the
function object directly to the onload property:

window.onload = function() {
/* ... */
};
var sCookie;

SetCookie("CookieTest","True");
sCookie = GetCookie("CookieTest");
I hope you check that the cookie property exists and is a string
before writing to it. If not, you'll create a cookie property which
will always contain whatever you assign to it. See
<URL:http://www.jibbering.com/faq/faq_notes/cookies.html>.
if (sCookie = "True")
That expression will always be true as you're assigning the string,
'True', to the sCookie variable. The comparison operator is two
consecutive equals symbols (==). A simple way to avoid this specific
example is to always specify literals and other "r-values"
(expressions that you cannot assign to) first:

if('true' = sCookie) {

In this case, the script engine would report an error as you cannot
assign to a string literal.
divNoCookies.style.display = "none";
divDisclaimer.style.display = "block";
Microsoft came up with (what I think is) a stupid idea where global
variables are created based on the id and name attributes of HTML
elements. This "feature" is not supported and all browsers and should
never be used. Instead, use the getElementById method (with
appropriate feature detection):

var disclaimer = null,
noCookies = null;

if(document.getElementById) {
disclaimer = document.getElementById('divDisclaimer');
noCookies = document.getElementById('divNoCookies');
}
if(disclaimer && disclaimer.style
&& noCookies && noCookies.style)
{
disclaimer.style.display = 'block';
noCookies.style.display = 'none';
}
<div ID="divDisclaimer" Name="divDisclaimer" style="display:none">
DIV elements do not have name attributes.
<div ID="divNoCookies" Name="divNoCookies" style="display:block">
<tr>
<td>
You don't seem to have a table, so you can hardly have table rows or
cells. Even if there is a TABLE element somewhere, a DIV element
cannot be its child. That is,

<table>
<div>

is invalid, however

<table>
<tr>
<td>
<div>

is fine. If you want to group table rows, use a TBODY element:

<table>
<tbody>
<tr><!-- ... --></tr>
<tr><!-- ... --></tr>
</tbody>
</table>
<FONT color=red>


The FONT element is deprecated. A better approach would be to give a P
element a warning class and style that red:

In a style sheet:

.warning {
color: red;
}

<p class="warning">
...
</p>

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
In article <11**********************@f14g2000cwb.googlegroups .com>,
ib*********@yahoo.com enlightened us with...
Howdy All,

I am trying to detect if the user has cookies enabled on a page and
display text accordingly. My cookie detection works but I can't get
the divs to work. Here is the javascript and html does anybody have
any sugestions?


Stop coding using vbscript syntax and operators when you're writing
javascript. :)

(see Michael's post for a more involved breakdown of the script's many
issues)

--
--
~kaeli~
"When dogma enters the brain, all intellectual activity
ceases" -- Robert Anton Wilson
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.