iammudassir Posted December 12, 2012 Share Posted December 12, 2012 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head> <body><html><head><script>function showUser(str){if (str=="") { document.getElementById("txtHint").value=""; 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","getuser.php?q="+str,true);xmlhttp.send();}</script></head><body> <form><select name="users" onchange="showUser(this.value)"><option value="">Select a person:</option><option value="1">1</option><option value="2">2</option></select><input name="buyername" type="text" id="txtHint" /> """" I WANT TO DISPLAY RESULT IN THIS FIELD"""" </form><br><div id="txtHint"><b>Person info will be listed here.</b></div> RESULT IS DISPLAYING HERE </body></html></body></html> QUESTION:I WANT TO DISPLAY RESULT IN MY INPUT FIELD<input name="buyername" type="text" id="txtHint" />AS YOU KNOW RESULT COMES FROMdocument.getElementById("txtHint").innerHTML=xmlhttp.responseText; Link to comment Share on other sites More sharing options...
Ingolme Posted December 12, 2012 Share Posted December 12, 2012 You need to set the value property, not the innerHTML property. 1 Link to comment Share on other sites More sharing options...
thescientist Posted December 12, 2012 Share Posted December 12, 2012 (edited) to supplement, input elements have a value property, every other element has the innerHTML property Edited December 12, 2012 by thescientist 1 Link to comment Share on other sites More sharing options...
iammudassir Posted December 13, 2012 Author Share Posted December 13, 2012 You need to set the value property, not the innerHTML property. i change my line like thisdocument.getElementById("txtHint").value=xmlhttp.responseText; '''''' here you can see i change innerHTML to Value , now it showing result in my INPUT field but like this <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><td>real</td></body></html> my result is only one word "REAL" but it shows above three lines in my input Field , please please correct my code i dont know JAVA and AJAx Link to comment Share on other sites More sharing options...
dsonesuk Posted December 13, 2012 Share Posted December 13, 2012 You have 2 elements with same id ref id="txtHint" when they should be unique within a page. that is the ref it returns the response to, remove from div element. Link to comment Share on other sites More sharing options...
Ingolme Posted December 13, 2012 Share Posted December 13, 2012 to supplement, input elements have a value property, every other element has the innerHTML propertyinput elements, like every other element, have an innerHTML property, but the innerHTML isn't what sets the text that's displayed in it. The innerHTML property just sets or returns the code that's between the two tags of the element. If, after setting the innerHTML property of an <input> element, you look at the generated DOM you should find it between <input> and </input> tags at least in theory. It's possible that browsers ignore any attempts to modify the innerHTML of an input. Link to comment Share on other sites More sharing options...
thescientist Posted December 13, 2012 Share Posted December 13, 2012 ah, good clarification. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now