Click to See Complete Forum and Search --> : Multiple-line variables?


CaseLogic
08-14-2004, 05:18 PM
I seriously doubt it's possible, but is there a way to extend a variable declaration to several lines? The reason I ask is because I want to assign a variable to some HTML for a form, so that I can assign it to an innerHTML later, but I don't want to have to put all that HTML onto one line. Is there a way to do the following:

var form = "<form method='post' action'this.php'>
<input type='text'>";


Something along those lines, but to a greater extent (more lines)? Or maybe an easier way to assign a variable to a block of HTML?

-Thanks

steelersfan88
08-14-2004, 05:56 PM
Concatenate the two lines, such as:<script type="text/javascript">

var str = "abc"
+ "def";

alert(str); // alerts "abcdef", no line feed!

</script>Dr. Script

CaseLogic
08-14-2004, 06:16 PM
Originally posted by steelersfan88
Concatenate the two lines, such as:<script type="text/javascript">

var str = "abc"
+ "def";

alert(str); // alerts "abcdef", no line feed!

</script>Dr. Script

That's exactly what I was looking for, thanks! Oh, and you don't by chance know of an easier way to do what I'm trying to (assuming I explained it properly)?

Charles
08-14-2004, 06:54 PM
1) Be careful that you aren't making a JavaScript dependent page. That would be bad, very bad.

2) Element.innerHTML is a MSIE corruption of JavaScript anyway. Just use the W3C DOM and build up your node one piece at a time:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>

<script type="text/javascript">
<!--

var node = document.createElement('ol')

var item1 = document.createElement('li')
item1.appendChild(document.createTextNode('fee'))
node.appendChild(item1)

var item2 = document.createElement('li')
item2.appendChild(document.createTextNode('fie'))
node.appendChild(item2)

var item3 = document.createElement('li')
item3.appendChild(document.createTextNode('foe'))
node.appendChild(item3)

var item4 = document.createElement('li')
item4.appendChild(document.createTextNode('fum'))
node.appendChild(item4)

onload = function () {
document.getElementsByTagName('BODY')[0].appendChild(node)
}
// -->
</script>

</head>
<body>
<h4>Example</h4>
</body>
</html>