View Full Version : write method delete "past space" string

06-24-2009, 06:15 AM

I'm quite new to JS, and I'm tring to write the document with document.write(),
but if there a space in the string it eliminate all the text after the space.
I tried this:

function _Start(){
var _string = "My Dog";
document.write("<a href=/"+'\"'+_string+'\"'+">Sample</a>");

My Dog
Sample {c:\..\"My}

I know that the reason is that the string needs to be under "" for not to elminate the text, but I just can't figure it out how to ...

06-24-2009, 05:54 PM
either of the following two options will work just fine, you were just escaping the wrong quotes:

document.write('<a href="'+_string+'">Sample</a>');
document.write("<a href=\""+_string+"\">Sample</a>");