PDA

View Full Version : Can variables hold html code as a value?


GREGO
08-26-2002, 12:59 AM
Hey all,

Just wondering if a variable can hold html cold as a value.

Ex - var code = <html><head>

like that,

cant that be done?

thanks

Dr. Web
08-26-2002, 01:55 AM
yes, didn;t you try it? What is your overall goal?

Jon Hanlon
08-26-2002, 07:05 PM
Of course you'd need quotes:

var code = "<html><head>"

This is typically used to get/set the innerHTML property in IE & NS6.
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/innerhtml.asp

GREGO
08-26-2002, 07:24 PM
Thanks guys, one more question: How do you know when a variable value needs quotes around it? And do you have to put "var" infront of the name?

Ex
Var test = 1
var test ="1"
test = 1
test = "1"

I have seen in books where they dont even use var, the just put name = value, sometimes the value has quotes sometimes it doesnt, how do I know when to do what?


BTW, its for a meta tag maker im working on.

Thanks guys

Jon Hanlon
08-26-2002, 07:29 PM
See here:
http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/ident.htm

I recommend always using var unless you intend accessing a global variable.

GREGO
08-26-2002, 10:48 PM
Thanks Jon, your always a big help