-
Watch for input to a text field
i've got a text fIeld that when the user inputs a bunch of characters I want it to make an ajax call to the db to either update the db or return some information.
I've tried to listen to the onTextChanged event but this only works if I post back to the server. Anyone have some advice?
I'm trying to do this in asp.net with microsofts ajax
-
I had the same issue but I was able to resolve it by placing the ajax script to the onblur event (of a text box I am assuming).
See how:
<html>
<input type="text" id="aj_ems" name="aj_ems" value="$aj_ems" size="6" maxlength="5" class="DataField" onblur="fnValidateEMS();"> <span class="Note" id="ems_val"></span>
</html>
<js>
function fnSortBy(_part, _fld)
{
document.getElementById('aj_sort_output').value = _part;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var _emsnum = document.getElementById('aj_ems').value;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
// Constructing URL
var url="ajax_sort_item.php";
url=url+"?partnum="+_part + "&field=" + _fld;
// Submitting URL to xmlHTTP
xmlHttp.onreadystatechange=stateChanged_SORT;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
// ****************************************************************************************** ******************
function stateChanged_SORT()
{
//alert(me);
var _sort_output;
if (xmlHttp.readyState==4)
{
_sort_output = document.getElementById('aj_sort_output').value;
alert(_sort_output);
document.getElementById('DIV_' + _sort_output).innerHTML=xmlHttp.responseText;
}
}
</js>
Good luck
-
Place the ajax script on OnBlur event.
function fnValidateEMS()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var _emsnum = document.getElementById('aj_ems').value;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
// Constructing URL
var url="ajax_ems_validate.php";
url=url+"?emsnum="+_emsnum;
url=url+"&sid="+Math.random();
// Submitting URL to xmlHTTP
xmlHttp.onreadystatechange=stateChanged_EMSVALIDATE;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
// ****************************************************************************************** ******************
function stateChanged_EMSVALIDATE()
{
//alert(me);
var _tri;
var _xmlstring;
if (xmlHttp.readyState==4)
{
_xmlstring = xmlHttp.responseText;
_tri = _xmlstring.indexOf('Invalid');
if(_tri == 0)
{
document.getElementById('ems_val').innerHTML=xmlHttp.responseText;
document.getElementById('aj_ems').value="";
}
else
{
document.getElementById('ems_val').innerHTML="<img src='" + icon_url + "/ok.gif' width='15' height='15' title='Valid Value'>";
document.getElementById('aj_ems').value=xmlHttp.responseText;
}
}
}
// ****************************************************************************************** ******************
-
Try to use the onblur event
Similar Threads
-
By chupacabra in forum VB Classic
Replies: 5
Last Post: 06-18-2007, 12:13 PM
-
Replies: 3
Last Post: 08-30-2001, 11:45 AM
-
By George Gilbert in forum vb.announcements
Replies: 0
Last Post: 08-19-2001, 11:34 AM
-
Replies: 2
Last Post: 06-29-2001, 09:17 AM
-
By Georgiana Trigg in forum VB Classic
Replies: 0
Last Post: 10-29-2000, 12:21 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|