JavaScript help please, thank you.

SteveMcQ

CAGiversary!
Feedback
15 (100%)
If you are only vaguely familiar with JS, please look away as this is complete gibberish. Anyway...

I'm trying to use "document.write" to display a user input on a very basic page. The thing is, I'm trying to have some sort of consistency as far as background, banners, etc. between the JS written page and the ones I've coded myself.

I'm able to display things properly with document.write, but I'm trying to add the background images, etc.

Specifically, I want to add the following code snippet inside document.write("....");

document.write("

MY TEXT

");

I can't get it to work right, though. I've been told that I have to add a '\' in front of " so the browser doesn't get confused, but even if I do that it still won't load. Is it the semi-colon tripping things up or what?

I hope that makes sense to someone.

Thanks.
 
Document.write is going to accept a string, therefore what you are passing in needs to be formatted correctly.

For example: document.write('Link')

Notice the " followed by single ' where you want to specify something, such as a variable. It's more than likely getting confused by your double quotes.


Edit: Do something like this... (I'm not on my work box or I'd test this)

var str='';
str+='';
str+='MY TEXT';
str+='';
document.write(str);
 
[quote name='mtxbass1']Document.write is going to accept a string, therefore what you are passing in needs to be formatted correctly.

For example: document.write('Link')

Notice the " followed by single ' where you want to specify something, such as a variable. It's more than likely getting confused by your double quotes.


Edit: Do something like this... (I'm not on my work box or I'd test this)

var str='';
str+='';
str+='MY TEXT';
str+='';
document.write(str);[/quote]That does work, thank you. We haven't been taught that way of doing it. So I would imagine if I wanted to insert a banner and navigational text, its the same basic idea.

Just so I understand your code example, the first line is just setting a string variable. Then the lines starting with "str+" are the values given to the string. Finally, those values are passed into document.write with the variable named 'str'.

So anything in a single quote (') is what is displayed directly on the page while the (") double quotes are for setting parameters.
 
[quote name='SteveMcQ']That does work, thank you. We haven't been taught that way of doing it. So I would imagine if I wanted to insert a banner and navigational text, its the same basic idea.

Just so I understand your code example, the first line is just setting a string variable. Then the lines starting with "str+" are the values given to the string. Finally, those values are passed into document.write with the variable named 'str'.

So anything in a single quote (') is what is displayed directly on the page while the (") double quotes are for setting parameters.[/quote]

Correct about the string variable. All "str+" is doing is appending what you tell it to to the string you already have.

The " and ' thing just basically makes it such that the script interpreter doesn't get confused.

Doing something like,

Document.write("This is a paragraph.

"); would still print "This is a paragraph" on the page (obviously without quotes).
 
If you are only vaguely familiar with JS, please look away as this is complete gibberish. Anyway...

I'm trying to use "document.write" to display a user input on a very basic page. The thing is, I'm trying to have some sort of consistency as far as background, banners, etc. between the JS written page and the ones I've coded myself.

I'm able to display things properly with document.write, but I'm trying to add the background images, etc.

Specifically, I want to add the following code snippet inside document.write("....");

document.write("

MY TEXT

");

I can't get it to work right, though. I've been told that I have to add a '\' in front of " so the browser doesn't get confused, but even if I do that it still won't load. Is it the semi-colon tripping things up or what?

I hope that makes sense to someone.

Thanks.
 
Document.write is going to accept a string, therefore what you are passing in needs to be formatted correctly.

For example: document.write('Link')

Notice the " followed by single ' where you want to specify something, such as a variable. It's more than likely getting confused by your double quotes.


Edit: Do something like this... (I'm not on my work box or I'd test this)

var str='';
str+='';
str+='MY TEXT';
str+='';
document.write(str);
 
[quote name='mtxbass1']Document.write is going to accept a string, therefore what you are passing in needs to be formatted correctly.

For example: document.write('Link')

Notice the " followed by single ' where you want to specify something, such as a variable. It's more than likely getting confused by your double quotes.


Edit: Do something like this... (I'm not on my work box or I'd test this)

var str='';
str+='';
str+='MY TEXT';
str+='';
document.write(str);[/quote]That does work, thank you. We haven't been taught that way of doing it. So I would imagine if I wanted to insert a banner and navigational text, its the same basic idea.

Just so I understand your code example, the first line is just setting a string variable. Then the lines starting with "str+" are the values given to the string. Finally, those values are passed into document.write with the variable named 'str'.

So anything in a single quote (') is what is displayed directly on the page while the (") double quotes are for setting parameters.
 
[quote name='SteveMcQ']That does work, thank you. We haven't been taught that way of doing it. So I would imagine if I wanted to insert a banner and navigational text, its the same basic idea.

Just so I understand your code example, the first line is just setting a string variable. Then the lines starting with "str+" are the values given to the string. Finally, those values are passed into document.write with the variable named 'str'.

So anything in a single quote (') is what is displayed directly on the page while the (") double quotes are for setting parameters.[/quote]

Correct about the string variable. All "str+" is doing is appending what you tell it to to the string you already have.

The " and ' thing just basically makes it such that the script interpreter doesn't get confused.

Doing something like,

Document.write("This is a paragraph.

"); would still print "This is a paragraph" on the page (obviously without quotes).
 
bread's done
Back
Top