Help converting DOM Javascript to JQuery
Hi everyone. New guy.
I'm super new to JQuery, and one of the first things I need to do is convert a small piece of Javascript to JQuery. I'm having a tough time finding any tutorials on the Web, so I was hoping someone could help me out or point in the right direction or whatever.
It's an easy piece of code that takes the data from one drop down menu and uses that to populate a second drop down:
-
<script>
function GetXmlHttpObject(handler) {
var objXMLHttp=null;
if (window.XMLHttpRequest) {
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject) {
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return objXMLHttp;
}
function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
document.getElementById("txtResult").innerHTML= xmlHttp.responseText;
}
else {
//alert(xmlHttp.status);
}
}
function htmlData(url, qStr) {
if (url.length==0) {
document.getElementById("txtResult").innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
alert ("Browser does not support HTTP Request");
return;
}
url=url+"?"+qStr;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true) ;
xmlHttp.send(null);
}
</script>
<form method="post">
<select name="option" onchange="htmlData('test.php', 'ch='+this.value)" />
<option value="#">-Select-</option>
<option value="Menu1">Menu1</option>
<option value="Menu2">Menu2</option>
</select>
<div id="txtResult"> <select name="List"><option></option></select> </div>
I assume I don't need to post the PHP. It just shows which data is passed via an if statement.
I know a few very simple things, like the $(document).ready(function(), and how to convert a getElementById, but that's about the extent of it so far.
Thanks everyone.