473,785 Members | 3,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.write - CSS problem??

Hi,

I'm a Javascript Newby. But that doesn't discourage me at all.
At this time I'm working on a little javascript-gimmick.

A white browser page filled with white (invissible for the viewer)
text. Every white text character has in case of a MouseOver an other
(randomly given) change cursor of one of the 15 different browser
cursors).
I found some example scripts to change the cursor and tried to
incoporate them with a text character generating loop and the
document.write function. But somehow it doesn't work like it should
be. I think that problem is that I can't get the the Java Script and
the CSS working properly together.

Anyone have some ideas or comments ?

Thanks!

here is the code where I'm working on

<head>
<title>Cursor Test Page</title>
<style type="text/css">
a.crosshair {cursor: crosshair;}
a.default {cursor: default;}
a.eastresize {cursor: e-resize;}
a.help {cursor: help;}
a.move {cursor: move;}
a.northresize {cursor: n-resize;}
a.northeastresi ze {cursor: ne-resize;}
a.northwestresi ze {cursor: nw-resize;}
a.pointer {cursor: pointer;}
a.southresize {cursor: s-resize;}
a.southeastresi ze {cursor: se-resize;}
a.southwestresi ze {cursor: sw-resize;}
a.text {cursor: text;}
a.westresize {cursor: w-resize;}
a.wait {cursor: wait;}
</style>
<SCRIPT LANGUAGE="JAVAS CRIPT">
<!--
var x = 0;
var cursorArray = new Array ();
cursorArray[0]= "crosshair" ;
cursorArray[1]= "default" ;
cursorArray[2]= "e-resize" ;
cursorArray[3]= "help" ;
cursorArray[4]= "move" ;
cursorArray[5]= "n-resize" ;
cursorArray[6]= "ne-resize" ;
cursorArray[7]= "nw-resize" ;
cursorArray[8]= "pointer" ;
cursorArray[9]= "s-resize" ;
cursorArray[10]= "se-resize" ;
cursorArray[11]= "sw-resize" ;
cursorArray[12]= "text" ;
cursorArray[13]= "w-resize" ;
cursorArray[14]= "wait" ;

do {
var R = Math.floor(math .random() *15);
document.write( "<a href="test" class=" + cursorArray[R] + ">A</a>");
x = x+1;
} while (x<900)
//-->
</SCRIPT>
</head>
Jul 23 '05
15 2831
Not to be outdone by Howard Dean, Michael Winter bellowed
<opsbz2hre1x13k vk@atlantis>:
x++


The unary increment is quite handy. IMO it looks neater too.
Does Javascript support pre-use unary increment/decrement, eg ++i?


Yes, JavaScript supports both pre- and post-increment/decrement.


Good to know, thanks :o)
I also like the alternate condition statement
<boolean_exp> ? <true_action> : <false_action >;
which is equivalent to
if (<boolean_exp> ) <true_action> ; else <false_action >;


I would argue that it should be used sparingly, though. I've seen
examples where several conditional operators are used nested, and
with no parentheses. It quickly becomes unreadable without careful
formatting. That said, it certainly can be very useful.


I agree. I usually only use it for simple things.
I find it particularly useful when I'm toggling a CSS value, say text color,
eg
mytext.style.co lor = mytext.style.co lor=="#ff0000" ? "#0000ff" :
"#ff0000";

--

Jason, aka The Blue Raja
Jul 23 '05 #11
On 31 Jul 2004 08:52:13 -0700, ma***@mptheunis sen.nl (marco) wrote:


If your learning by a good book, I recommend the following:

javascript: The Definitive guide
by David Flanagan
publisher: O'Reilly
ISBN: 0-596-00048-0
HTH

Al


Hahahahaha.
Guess what I just bought in the bookstore some 10 minutes ago!
Thanks, I'll take a look at your comments and see if I (with the new
O'Reilly in my possession) can work it out.

When I first picked the book up a couple of weeks (recommend to be by
others) I wasn't sure at first if its the one I really wanted.... but
after a couple of weeks reading, I understand things a LOT better now,
things like "prototype" , and how functions can be assigned to
variables etc (and why) and it looks an excellent reference source
and easy to find things that you might want. eg how do you get the
text that a user has typed in a text box... is it "element.te xt" or
"element.value" , with a quick look you have the answer.

Al.
Jul 23 '05 #12
On 31 Jul 2004 10:24:49 -0700, ma***@mptheunis sen.nl (marco) wrote:
OK. It works!! :-)

The main problem was the quote issue.
I needed an extra set of quotes in the -- class=" + cursorArray[R] +
"-- part.
Now it is like this: -- class="' + cursorArray[R] + '" And it works
fine.
Indeed it is a good advice to use the double quotes for distincting
the HTML and the single quotes for the JavaScript strings. It's saves
a lot of problems.


Yes, this was the Main problem with your code, also some of the
classnames in "cursorArra y[R]" didn't match the names in the <style>

Glad you have it working now :)

Al.
Jul 23 '05 #13
"Blue Raja" <th************ ********@iprimu s.com.au> writes:
I also like the alternate condition statement
<boolean_exp> ? <true_action> : <false_action >;
which is equivalent to
if (<boolean_exp> ) <true_action> ; else <false_action >;


It's not really equivalent, more like parallel.

In Javascript, as in most langauges, there are (at least) two
different syntactic categories: statements and expressions.

Expressions are evaluated and their result is a value. Examples
are "2+2" or "Math.sin(Math. asin(Math.PI))" . You can combine
expressions into other expressions using operators or functions.

Statements are executed and their result is a change of state. They
do not have a value. Examples are "for(...){. ..}" and
"if(...){.. .}". You can put several statements together by
juxtaposition, and you can group them with "{" and "}".

The "if" statement is a conditional statement. It is a choice between
one of two statments, based on the value of an expression. Since doing
nothing is a (trivial) change of state, you can even omit one of the
statements (the "else" branch).

The "?:" operator defines a conditional expression. It is a choice
between one of two expressions, based on the value of a third. Since
an expression must have a value, you can not omit one of the expressions.
A "conditiona l whatever" is a general concept in programming. For most
syntactic categories, it makes sense to have an either/or choice
between two different possibilities. Javascript, as most C-based
languages only have conditional statements and expressions (the only
other syntactic category in C was the declaration, which is harder
to make conditional).

In general, a "conditiona l whatever" is itself a "whatever", and it
contains two "whatever"' s and a condition expression that chooses
between them. The "if" statement and the "?:" expression are examples
of this general concept.

The switch/case statement is a generalization, where there are more
than two different statements to choose between.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #14
Not to be outdone by Howard Dean, Lasse Reichstein Nielsen bellowed
d6**********@ho tpop.com:
I also like the alternate condition statement
<boolean_exp> ? <true_action> : <false_action >;
which is equivalent to
if (<boolean_exp> ) <true_action> ; else <false_action >;


It's not really equivalent, more like parallel.

In Javascript, as in most langauges, there are (at least) two
different syntactic categories: statements and expressions.

<snip>

All quite right, and an oversight on my part for implying the two were
equal.
Really the first should be more like
<boolean_exp> ? <true_value> : <false_value> ;

This is why I don't do as well as I could at exam time -- too much coding,
not enough theory ;o)

--

Jason, aka The Blue Raja
Jul 23 '05 #15
Harag <ha************ *@softhome.com> wrote in message news:<rm******* *************** **********@4ax. com>...
On 31 Jul 2004 08:52:13 -0700, ma***@mptheunis sen.nl (marco) wrote:


If your learning by a good book, I recommend the following:

javascript: The Definitive guide
by David Flanagan
publisher: O'Reilly
ISBN: 0-596-00048-0
HTH

Al


Hahahahaha.
Guess what I just bought in the bookstore some 10 minutes ago!
Thanks, I'll take a look at your comments and see if I (with the new
O'Reilly in my possession) can work it out.

When I first picked the book up a couple of weeks (recommend to be by
others) I wasn't sure at first if its the one I really wanted.... but
after a couple of weeks reading, I understand things a LOT better now,
things like "prototype" , and how functions can be assigned to
variables etc (and why) and it looks an excellent reference source
and easy to find things that you might want. eg how do you get the
text that a user has typed in a text box... is it "element.te xt" or
"element.value" , with a quick look you have the answer.

Al.


Well I know now one thing for sure the O'Reilly's books are the BEST!
Stricktly speaking I bought the ‘Dynamic HTML' The Definitive
Reference By Danny Goodman. It contains HTML 4.01, XHTML, CSS Level 2,
DOM Level 2, and Javascript 1.5.
It's one of those +2 inches thick books and really expensive (61
euro's). I had some second thoughts about it when I saw that price but
I think/hope it's going to be a good investment.
I just noticed that the other book which I first used and borrowed
from the library is also from the same author(Danny Goodman) but an
other publisher. But that one is really bad in my opinion. No good
content structure and from that book I got all those obsolete kapital
and comments tags. I stick with O'Reilly.

Marco
Jul 23 '05 #16

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

Similar topics

9
6359
by: James Marshall | last post by:
I'm writing a library where I want to override document.write(), but for all document objects; thus, I want to put it in the prototype. I tried Document.prototype.write= my_doc_write ; but it didn't work. I discovered that this seemed to work: HTMLDocument.prototype.write= my_doc_write ; Why does HTMLDocument work here but not Document? Will this second
2
2386
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of copying/pasting everytime I change it, I figure this will be better, as I only change it once. The problem is, document.write doesn't handle multiple lines very well, so I was wondering what is the best way to do this? Maybe there is even a better...
12
1158
by: *.* | last post by:
Hey- I seem to be having a problem with the document.lastModified property. The way it is suppose to work is that it returns the date and time at which the document was last modified. IN my case it is returning the current date and time. It only does this when it is on the webserver. the code is: <script type="text/javascript"><!-- function footer(){
13
9651
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
4
2953
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400, like DOS, uses memory-mapped display, two bytes per character (one char byte and one attribute byte). We can get the screen offset allright, and I've written a javascript which does the math to convert the offset into row/col (i.e. left, top)...
12
2869
by: Sean | last post by:
Hi, I have the following script: ----------------------------------------------------------------------------------- <script type="text/javaScript"> <!-- document.write('<div id=hello1>Hello1</div>'); document.write('<div id=hello2 style="display:none;"><script src="test.js"><\/script></div>');
136
9457
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
11
3113
by: Michael Powe | last post by:
How can I make an XHTML-compliant form of an expression in this format: document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>"); this turns out to be a non-trivial exercise. inserting '&lt;' and '&gt;' causes the browser to write the text to the page as literal text rather than as the intended script element. Using escape codes seemed to work (makes it standard compliant) but the text is not written to...
2
2626
by: ethandbrown | last post by:
Hi All-- I'm a bit stymied here. I need to display arbitrary HTML obtained through AJAX. The problem is when a <script> block is encountered one can't use innerHTML to set the content, because the <script> block won't be evaluated. Googling around, a found the createContextualFragment() solution which does execute script code. The following, for example, works:
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10319
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.