phpchick 07-13-2012, 06:16 PM I'm launching the below javascript with an onChange event in the html:
<select name="date" onChange="showUser(this.value)">
I've verified that the onChange event is getting to the javascript by doing a simple alert("working"); and IE did fire up the alert, however the actual code that I want does not seem to work. (its functional in FF, Chrome, Safari, iPad, and Android).
What the function does is: take the value passed to it through the onchange, and send it to a php file as a variable. The php file takes the variable it gets and inserts it into a DB. I don't think the php portion is the problem because it works in every other browser. Does anyone have any insight?
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","http://testest.com/itgoeshere.php?q="+str,true);
xmlhttp.send();
}
Logic Ali 07-13-2012, 06:25 PM If you have not explicitly added value attributes to each <option> tag, you must do so for I.E.
phpchick 07-13-2012, 06:34 PM If you have not explicitly added value attributes to each <option> tag, you must do so for I.E.
Here's an example for what the select statement looks like, so they definitely all have values assigned.
<select name="date" onChange="showUser(this.value)">
<option value="">---</option>
<option value="1">Past hour</option>
<option value="2">Past week</option>
<option value="3">Past month</option>
<option value="4">Past year</option>
</select>
Philip M 07-13-2012, 07:48 PM <select name="date" onchange="showUser(this.value)">
<option value="">---</option>
<option value="1">Past hour</option>
<option value="2">Past week</option>
<option value="3">Past month</option>
<option value="4">Past year</option>
</select>
<script type = "text/javascript">
function showUser(which) {
alert (which);
}
</script>
Works fine for me in all browsers.
"I am not a vegetarian because I love animals; I am a vegetarian because I hate plants." - A. Whitney Brown.
Old Pedant 07-13-2012, 09:07 PM Code looks right to me, and I have used nearly identical code in IE (and all other browsers) many times.
But you could (a) use the MSIE debugger and/or (b) put in a bunch more alerts to see where you are getting to.
Example:
function showUser(str)
{
alert("showUser(" + str + ") was called");
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
alert("using XMLHttpRequest");
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
alert("using ActiveXObject");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert("got response");
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://testest.com/itgoeshere.php?q="+str,true);
alert("opened xmlhttp");
try {
xmlhttp.send();
alert("called send");
} catch ( e ) {
alert"error in send " + e.toString() );
}
}
phpchick 07-13-2012, 09:11 PM Good idea, pendant, trying that now.
phpchick 07-13-2012, 09:20 PM With the code you provided, it completely bombs out. No alerts, no anything.
Old Pedant 07-13-2012, 09:23 PM A typo.
alert"error in send " + e.toString() );
Missing the initial (
alert("error in send " + e.toString() );
If you would use the error console in ANY browser it would tell you about that.
Old Pedant 07-13-2012, 09:24 PM Good idea, pendant, trying that now.
Why does everybody thing I'm a dangling object?
http://dictionary.reference.com/browse/pedantic
Definition 2 fits. You *need* to be "overly concerned with minute details or formalisms" when you are coding.
phpchick 07-13-2012, 09:26 PM Why does everybody thing I'm a dangling object?
http://en.wikipedia.org/wiki/Pedant
Haha, sorry. Yeah, I caught that error, sorry about that. debugging now...
phpchick 07-13-2012, 10:03 PM Why does everybody thing I'm a dangling object?
http://dictionary.reference.com/browse/pedantic
Definition 2 fits. You *need* to be "overly concerned with minute details or formalisms" when you are coding.
Mr. Pedant You are never going to believe this.
So I added the alerts and the code started working in IE.
I then commented out the alerts, and it continued to work, so I guess that's our answer?
I have no idea how that works? How could the addition of the alerts have solved it?
Old Pedant 07-13-2012, 10:05 PM I would *GUESS* the IE was caching an old version of your page when you had the problem before. But that's just a guess.
As I said, the code looked right to me the first time around.
|
|