Jump to content

mseerob

Members
  • Posts

    17
  • Joined

  • Last visited

Everything posted by mseerob

  1. <html><head><script src="selectuser.js"></script></head><body><form onSubmit="showUsers(this); return false"> <p>Select a User: <select name="users"> <option value="Peter">Peter Griffin</option> <option value="Lois">Lois Griffin</option> <option value="Glenn">Glenn Quagmire</option> <option value="Joseph">Joseph Swanson</option> </select></p> <p> <input name="username" type="text" id="username"> </p> <p> <input type="submit" id="submit_button" name="Submit" value="Submit"></p></form><p><div id="txtHint"><b>User info will be listed here.</b></div></p></body></html> Everything is good but now when I press Submit it keeps showing..[object HTMLFormElement]In the javascript console it says: Element referenced by ID/NAME in the global scope.I have encountered this problem before but I do not remember how to fix this issue..
  2. I got it work..... var xmlHttpfunction showUser(str){ xmlHttp=GetXmlHttpObject()if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="grabdata.php"var params = "users=Lois"xmlHttp.onreadystatechange=stateChanged xmlHttp.open("POST",url,true)xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");xmlHttp.setRequestHeader("Content-Length", params.length);xmlHttp.send(params)}function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("txtHint").innerHTML=xmlHttp.responseText } }function GetXmlHttpObject(){var xmlHttp=null;try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e) { //Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }return xmlHttp;} I am still concerned. I removed this code from there url=url+"&sid="+Math.random() I was told that with this code it prevents it from being cached. Is this needed since Im using the POST method?and another thing Im having trouble with is this. You'll notice this.. var params = "users=Lois" Using this str.users.value is not correct. How can I fix this?
  3. I have became more interested in Ajax and from the use of it, I learned that it can make the process sooo much faster than before in my web applications. I first started using this script to get me started var xmlHttpfunction showUser(str){ xmlHttp=GetXmlHttpObject()if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="selectusers.php"url=url+"?q="+strurl=url+"&sid="+Math.random()xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true)xmlHttp.send(null)}function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("totalusersDIV").innerHTML=xmlHttp.responseText } }function GetXmlHttpObject(){var xmlHttp=null;try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e) { //Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }return xmlHttp;} I would like to start using the POST method instead of GET because of the limitations of the query string. It would be much appreciated if someone could suggest on how change the coding so its using the POST method.
×
×
  • Create New...