Jump to content

document.getElementById ISSUE


Recommended Posts

<!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 post
Share on other sites

to supplement, input elements have a value property, every other element has the innerHTML property

Edited by thescientist
  • Like 1
Link to post
Share on other sites
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 post
Share on other sites
to supplement, input elements have a value property, every other element has the innerHTML property
input 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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...