I have a textarea that I want to fill using ajax if javascript is enabled in the user's browser, but use php if js is disabled. The problem is, both the ajax and the php will execute, creating a double of every input entered. I tried a noscript tag, but then nothing prints out. I would greatly appreciate any help.
Here's my html:
<form action="savemessage.php" method="post" id="mainChat" name="mainChat"
onsubmit="return loadChat();">
<textarea class="historyClass" id="historyFieldjs" name="historyFieldjs" rows="40" cols="80">
<noscript>
<textarea class="historyClass" id="historyField" name="historyField" rows="40" cols="80">
<?php
echo "stuff";
?>
</textarea></noscript>
And javascript:
function loadChat()
{
var xmlhttp = new XMLHttpRequest;
xmlhttp.open("GET", "getmessages.php", true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
var results = JSON.parse(xmlhttp.responseText);
var i;
for(i=0; i<results.length; i++)
{
document.getElementById("historyFieldjs").value=
document.getElementById("historyFieldjs").value+result[i]+"\n";
}
}
}
return false;
}