Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript autofill/suggest box problems

Status
Not open for further replies.

Jimi2Cool

Programmer
Jul 30, 2007
25
0
0
US
Ok, I’m trying to implement this javascript/ajax autofill control that uses a webservice to get a list of strings matching the users input. I have nearly everything working proper but one part. It seems no matter what way I try things I can never get the current value of the textbox on a keypress or keydown event. If I try to getelementbyid I get the textbox but the value is “” no matter wat the actual current text is. As a quick way around this I declare a global var to hold the text as it gets typed which is bad because when text is pasted or selected and deleted I get no message. The onchanmge event only fires when I hit enter. I know I must be approaching this wrong because I’ve seen this done before and the solution I saw accounted for all this. Anyone have and examples/advice working withthese events and text inputs?
 
Hey I had a similar issue. Here is an example file i had made. Note: I made this in Firefox 2.0. I am 99% sure IE has different way of handling events. If you use this approach you will need to do some research on it.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<script language = "javascript" type="text/javascript">
var textin;

function getTextValue(evt){
textin.innerHTML = evt.target.value; //evt.target = reference to txtFld
}

window.onload = function() {
var inputText = document.getElementById('txtFld');
textin = document.getElementById('textin');
inputText.onkeyup = getTextValue;
};

</script>

</script>




</head>


<body>

<div id="content"></div>
<input type="text" size="20" id="txtFld" >

<div id="textin"></div>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top