Forum Moderators: open
== index.html ==
<script language="JavaScript" type="text/javascript" src="aj.js">
</script>
<input type="text" value="#CCC" id="paints" size="7">
<input type="button" value="submit" id="gColor" onclick=
"handleIT();colorIT()"> <input type="text" id="textBack">
<div class="c1" id="divBack">Dynamically Paint Here.</div>
== aj.php ==
<?php
$paint = trim($_POST['paints']);
echo trim($paint);
?>
==aj.js ==
function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest();} else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP");} else {}}var search7 = getXmlHttpRequestObject();
function handleIT() { if (search7.readyState == 4 ¦¦ search7.readyState == 0) {
var paints = escape(document.getElementById('paints').value);
var parameters="paints="+paints;
search7.open("POST", 'aj.php', true);
search7.onreadystatechange = colorIT;
search7.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
search7.send(parameters);
}}
function colorIT() { if (search7.readyState == 4) {
var paints = escape(document.getElementById('paints').value);
document.getElementById("textBack").value=search7.responseText;
document.getElementById("divBack").style.backgroundColor=search7.responseText;
}}
===== IE Team Response =====
From an analysis of the IE folks, it seems that the problem is generated by some whitespace in your string
00380023 00380038 0000000a
This fails:
document.getElementById("divBack").style.backgroundColor=search7.responseText;
Error is Invalid property value.
- remove newline from php with text editor
- remove the ?> line completely
- change this
document.getElementById("textBack").value=search7.responseText;
document.getElementById("divBack").style.backgroundColor=search7.responseText;
to
var str = search7.responseText.split(/\s/g)[0]; // get first word
document.getElementById("textBack").value=str;
document.getElementById("divBack").style.backgroundColor=str;
That should solve the issue, but there should be more checks, for example entries like "hot pink" will still bomb.