Jump to content

String Problem


ajaxiskey

Recommended Posts

How can I make this string work?

 

document.getElementById("PAGE").innerHTML = '<div style="color: #FE4D1B; text-align: center; font-family: Arial; font-size: 12px; background-color: #222222;">View Comments</div><div id="VCP_COMMENTS" style="height: 166px; overflow: auto; border: 1px dotted #444444; width: 444px; margin: auto; margin-top: 4px;"></div><div id="VCP_BOX" style="text-align: center;"><textarea id="VCP_CONTENT" style="background-color: #000000; color: #FFFFFF; border: 1px dotted #FE4D1B; width: 444px; font-size: 10px; height: 30px; font-family: Arial; margin: auto; margin-top: 4px;"></textarea><input type="button" value="Post Comment" onClick="POST_NEWS_COMMENT('+NEWS_ID+',document.getElementById("VCP_CONTENT").value);" style="margin-top: 2px; background-color: #000000; color: #FFFFFF; border: 1px dotted #FE4D1B; width: 446px; font-family: Arial;"></div>';

Link to comment
https://forums.phpfreaks.com/topic/210505-string-problem/
Share on other sites

Create the string before hand, and do it over multiple lines, so it's easier to read:

 

var string = '<div style="color: #FE4D1B; text-align: center; font-family: Arial; font-size: 12px; background-color: #222222;">View Comments</div>';
string += '<div id="VCP_COMMENTS" style="height: 166px; overflow: auto; border: 1px dotted #444444; width: 444px; margin: auto; margin-top: 4px;"></div>';
string += '<div id="VCP_BOX" style="text-align: center;"><textarea id="VCP_CONTENT" style="background-color: #000000; color: #FFFFFF; border: 1px dotted #FE4D1B; width: 444px; font-size: 10px; height: 30px; font-family: Arial; margin: auto; margin-top: 4px;"></textarea>';
string += '<input type="button" value="Post Comment" onClick="javascript: POST_NEWS_COMMENT(' + NEWS_ID + ',\'' + document.getElementById("VCP_CONTENT").value + '\');" style="margin-top: 2px; background-color: #000000; color: #FFFFFF; border: 1px dotted #FE4D1B; width: 446px; font-family: Arial;"></div>';

document.getElementById("PAGE").innerHTML = string;

 

I fixed a few things up where you broke out of the string for the JavaScript variable and for where you got the value of a field. I also surrounded that with escaped single quotes.

Link to comment
https://forums.phpfreaks.com/topic/210505-string-problem/#findComment-1098352
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.