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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.