PDA

View Full Version : I'm a newbie...please help!"



sunline25
Aug 17th, 2002, 10:01 PM
About the quotation marks. Followings are scripts I wrote:

document.write("<A HREF=http://" +location.host+ "/index.html>Click Here for the HTML Goodies Home Page</A>")
document.write("Click <A HREF=http://"+location.host+"/index.htm>Here</A> for the Sunny Home Page.");
document.write("<BR><BR><BR>Thank you for coming in from <A HREF= document.referrer>" + document.referrer.title + "</A>");
document.write(" to <A HREF= document.location >" + document.title + "</A>,");
document.write("<BR><BR>Click <A HREF= 'index.htm'>Here</A> for the local Sunny Home Page.");


Which are correct?

TemperedSteel
Aug 17th, 2002, 10:09 PM
could you specify what you mean a little more please.

sunline25
Aug 17th, 2002, 10:23 PM
I was practicing the document.write method for some links but encountered error with the quoatation marks. The following one was copied from web site:
document.write("<A HREF=http://" +location.host+ "/index.html>Click Here for the HTML Goodies Home Page</A>")

I think it is correct. But I just couldn't figure out where and when to put quotation marks. The script I wrote is:
document.write("Click <A HREF='http://'+ location.host +'/index.htm'>Here</A> for the Sunny Home Page.");

But it didn't work. Please help!

um...
Aug 17th, 2002, 10:42 PM
<script language="Javascript">document.write("Click <A HREF='http://'+ location.host+'/index.htm'>Here</a> for the Sunny Home Page.");</script>
:thumbsup: :thumbsup: :thumbsup:

sunline25
Aug 17th, 2002, 11:13 PM
Sorry, it didn't work.

Owl
Aug 18th, 2002, 12:03 AM
Hi sunline25,


document.write("Click <A HREF='http://"+ location.host+"/index.htm'>Here</a> for the Sunny Home Page.");( ) ( )
>>V

beetle
Aug 18th, 2002, 12:37 AM
Here are some basic rules for string concatenation[list=1] Always start and end literals with the same quote type (single/double)
Dont switch between single/double during a concatenation
If you are encasing HTML, better to use single for the literals, and doubles for the HTML (not a rule, per se, but better IMHO)
If you need both, make sure to escape the quote properly with the backslash
[/list=1] Here are some examples of those rules[list=1] var string = "Hello World!";
NOT
var string="Hello World';

var string = "Hello" + " " + "World!";
NOT
var string = "Hello" + ' ' + "World!";

var pageHTML = '<body text="#000000">';
NOT
var pageHTML = "<body text='#000000'>";

var pageHTML = '<body onLoad="alert(\\'Hello World\\');">';
NOT
var pageHTML = '<body onLoad="alert('Hello World');">';
[/list=1] So, to properly modify the document.write you are using, it should be like this
document.write('Click <A HREF="http://' + location.host+ '/index.htm">Here</a> for the Sunny Home Page.');Oh, and in this case, it would probably be better to use document.writeln() instead of document.write()

Roy Sinclair
Aug 19th, 2002, 04:52 AM
If you are encasing HTML, better to use single for the literals, and doubles for the HTML (not a rule, per se, but better IMHO)

Follow that one as a rule. With xHTML 1.0 <tag attribute='value'> and <tag attribute=value> are not legal, <tag attribute="value"> is the legal html. Current browsers will accept the bad forms but it's becoming more and more apparent that making browsers forgive the bad coding habits is a major source of web pages that end up on the web as broken pages. Writing valid code (and checking it with a validator) is becoming much more important, now is the time to work on ridding yourself of the bad habits.

As a related note, tags and their attributes must all be lower-case in xHTML 1.0 as well, that's a big problem too since a lot of page writing tools generate upper case tags and attributes.

sunline25
Aug 19th, 2002, 02:24 PM
Thanks, your guys. This is a good site.