JavaScript addContent function – Packaging Options

5 pts.
Tags:
JavaScript
JavaScript forms
MySQL
PHP
Web development
* IS THERE A WAY to use this javascript addContent function, * Incorporate the utility of an ADD button * But avoid using the packaging of FORMS? While making use of a sample for addContent (located at http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/, I stumbled into a problem that I hope someone can help on. We have a PHP/MySQL page that has to be modified to ADD rows for data entry when needed. I have abandoned the traditional DOM object methods of adding a single row, since in this case the addition would be a whole block of rows. I don't think I'm smart enough to do that... Anyway, an idea hit me to make use of our MySQL dB and store the rows in there, and retrieve them using their method. <script language="javascript"> function addContent(divName, content) { document.getElementById(divName).innerHTML = content; } </script> <form name="myForm"> Content to be added: <textarea name="myContent"><?php echo $_value ?></textarea> <input type="button" value="Add content" onClick="addContent('myDiv', document.myForm.myContent.value); setCookie('content', document.myForm.myContent.value, 7);"> </form> <br><br> Your content will be added dynamically below: <div id="myDiv"></div> Skipping an ultimate requirement that the content of the addition be invisible and inaccessible, I tried the above out. It works, but the variable ($_value) has form elements in it, including <TEXTAREA></TEXTAREA>. The close of the tag, interrupts the value and throws the remaining code to the page, not awaiting insertion by the Submit Button. Example: [url]http://www.facey.com/insert_content1.php[/url] The Submit button successfully produces the part that stayed inside, but you see my problem. IS THERE A WAY to use this javascript addContent function, incorporate the utility of an ADD button but avoid using the packaging of FORMS? Thanks for any help! Bryan [EMAIL="bfox@facey.com">bfox@facey.com[/EMAIL] p.s. The PHP is transparent. Direct inclusion of the HTML contained in the variable as the value of TEXTAREA produces the same result.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Escape your markup characters inside $_value before echoing them, e.g. < to &lt;, > to &gt;, etc…

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following