AJAX: textarea this.value???
Posted: Thu Nov 04, 2010 10:58 am
I am brand new to using Ajax in PHP.
I have gone thru a few tutorials to try and grasp it.
I have come up with a real need for it on our of our web sites.
The premise is to stop people entering certain HTML code, like FONT into a box. Or even Pasting it from formatted text in MS Word.
Below is what I have tried (the important part of the code), but as a clear novice, I am obviously missing something.
The HTML content is pasted in. OnChange, it should be going to htmlcheck.php. That page checks thru preg_match for illegal code. If it finds some, it echos the warning. That warning should be in the DIV ID box.
What am I doing wrong?
[text]Update: it works if I use it on the input text part, that would have a "value" in it.
ie. <input type ='text' value=''>
But won't on the <textarea> as there is no 'value' to it. Is that right ?? Is there a workaround?
[/text]
I have gone thru a few tutorials to try and grasp it.
I have come up with a real need for it on our of our web sites.
The premise is to stop people entering certain HTML code, like FONT into a box. Or even Pasting it from formatted text in MS Word.
Below is what I have tried (the important part of the code), but as a clear novice, I am obviously missing something.
The HTML content is pasted in. OnChange, it should be going to htmlcheck.php. That page checks thru preg_match for illegal code. If it finds some, it echos the warning. That warning should be in the DIV ID box.
What am I doing wrong?
Code: Select all
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","htmlcheck.php?q="+str,true);
xmlhttp.send();
}
</script>
<textarea id='elm1' name='description' rows='6' cols='40' onchange=\"showUser(this.value)\"></textarea>
<br/>
<div id='txtHint'> </div>
Code: Select all
<?php
$q=$_GET["q"];
if (preg_match("/font/i", "$q")) { echo "<div class='warningbox'><b>ERROR</B><BR/>
The content you have entered contains invalid HTML for your web site.<br/>
We strongly suggest you paste your text into Notepad and then copy/paste that text into the box above and format using the buttons beneath.<br/></div>";}
?>
ie. <input type ='text' value=''>
But won't on the <textarea> as there is no 'value' to it. Is that right ?? Is there a workaround?
[/text]