Forum Moderators: open

Message Too Old, No Replies

help with document.write and browser output

         

electricocean

4:03 am on Jun 27, 2005 (gmt 0)

10+ Year Member



Hi,

I am not sure about this:

document.write('<a href="#doc">meet the doctor</a>' + 'and his awesome friend <a href="#doc_fri">here</a>');

can you please explain the ' + ' part? and why do you put it where you put it?

I have this huge block of code that might need it.

electricocean

Dijkgraaf

5:02 am on Jun 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd say at some point they had a variable there that the wanted to have printed out, e.g. they had
' + doctorsname + '
and then they removed + doctorsname and didn't tidy it up further.
So you can safely remove the ' + ' and it should work fine

electricocean

5:54 am on Jun 27, 2005 (gmt 0)

10+ Year Member



Thanks.

well thing is this:

function displayJoke(jgenre, jtitle, jjoke, jrating, jbgcolor){
var w = window.open('',jtitle,'width=500,height=500,scrollbars=yes,resizable=yes');
var d = w.document;
d.write('<html><head><title>DKicks Jokes / Jokes / ' + jgenre + ' / ' + jtitle + '</title></head>
<body bgcolor="' + jbgcolor + '">' + 'DKicks Jokes / Jokes / ' + jgenre + ' / ' + jtitle + '<br>
<p align="center"><table><tr><td><font size="30">' + title + '</font></td>
<td>Current Rating: <img src="images/rate_star_' + jrating + '.jpg" />
<input type="button" value="Rate This Joke" onclick="location.href='rate_joke.php';"></td></tr></table></p>
<p align="center">' + jjoke + '</p><br></body></html>');
d.close();
w.focus();
}

I think it's messed up and I need to do something with it. If anyone can help me w/ that, it would be great

electricocean

Dijkgraaf

4:58 am on Jun 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, messed up all right
The first mistake is that in the window.open it needs to have jtitle.value rather than just jtitle.

For the rest it is a lot easier to find out where it is going wrong (and a lot easier to read) if you do the write's over several lines, see example below.
Do that bit by bit correcting mistakes as you go and eventually it should all work.

function displayJoke(jgenre, jtitle, jjoke, jrating, jbgcolor){
var w = window.open('',jtitle.value,'width=500,height=500,scrollbars=yes,resizable=yes');
var d = w.document;
d.write('<html><head><title>DKicks Jokes / Jokes / ' + jgenre + ' / ' + jtitle + '</title><body bgcolor="' + jbgcolor + '">');
d.write('DKicks Jokes / Jokes / ' + jgenre + ' / ' + jtitle + '<br>');
// rest of writes here
d.write('</body></html>');
}

electricocean

7:34 pm on Jul 2, 2005 (gmt 0)

10+ Year Member



Than you so much. The pop up window opens now except it doesn't read the other d.writes, the ones I write where it says "// rest of writes here ". I am not sure. My code now looks like this:

function displayJoke(jgenre, jtitle, jjoke, jrating, jbgcolor){
var w = window.open('',jtitle.value,'width=500,height=500,scrollbars=yes,resizable=yes');
var d = w.document;
d.write('<html><head><title>DKicks Jokes / Jokes / ' + jgenre + ' / ' + jtitle + '</title><body bgcolor="' + jbgcolor + '">');
d.write('DKicks Jokes / Jokes / ' + jgenre + ' / ' + jtitle + '<br>');
d.write('<p align="center"><table><tr><td><font size="30">' + jtitle + '</font></td>');
d.write('<td>Current Rating: <img src="images/rate_star_' + jrating + '.jpg" /> <input type="button" value="Rate This Joke" onclick="location.href=\"http://dkicks.dk.funpic.org/index.php?pageid=2&style=rate&joke=' + jtitle + '\";"></td></tr></table></p>');
d.write('<p align="center">' + jjoke + '</p><br><a href="#" onclick=" self.close()">Close Window</a></p>');

d.write('</body></html>');
d.close();
w.focus();
}

The pop-up window reads everything except the BOLD lines.
When I look at the source code throu my site (not in dreamweaver but in safari) it shows all my code normally like I would expect but it doesn't work.

thanks
electricocean

electricocean

7:36 pm on Jul 2, 2005 (gmt 0)

10+ Year Member



I fixed it thank you