While making use of a sample for addContent (located at http://www.randomsnippets.com - specific page here ) I stumbled into a problem that I hope someone can help on. This may not be the best/only way to skin this cat, but 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>, and the close of that tag interrupts the value and throws the remaining code to the page, not awaiting insertion by the Submit Button. Example: http://www.facey.com/insert_content1.php

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 SNIPPED>


p.s. The PHP is transparent. Direct inclusion of the HTML contained in the variable as the value of TEXTAREA produces the same result.

Perhaps I do not fully understand what you want, if so just explain a bit further, but from what I've read I created this code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<style type="text/css">
			#myDiv {
				width: 400px;
				height: 300px;
				background-color: #bbbbbb;
				overflow: scroll;
			}
		</style>
		<script type="text/javascript">
			function addContent(divName) {
			    document.getElementById(divName).innerHTML += document.getElementById('myContent').value + " ";
			}
		</script>
	</head>
	
	<body>
		<form name="myForm">

		Content to be added:
		<textarea id="myContent"></textarea>
		<input type="button" value="Add content" onClick="javscript:addContent('myDiv');">

		</form>

		<br><br>
		Your content will be added dynamically below:
		<div id="myDiv"></div>
	</body>
</html>

I left out the php in this by the way. Don't hesitate to ask questions, hope this helps : )

This article has been dead for over six months. Start a new discussion instead.