DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Watch for input to a text field

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Posts
    1

    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

  2. #2
    Join Date
    Jul 2007
    Location
    Chicago
    Posts
    5
    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

  3. #3
    Join Date
    Jul 2007
    Location
    Chicago
    Posts
    5
    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;
    }
    }
    }
    // ****************************************************************************************** ******************

  4. #4
    Join Date
    Jul 2007
    Location
    Chicago
    Posts
    5
    Try to use the onblur event

Similar Threads

  1. Replies: 5
    Last Post: 06-18-2007, 12:13 PM
  2. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM
  3. Double Text 1.0
    By George Gilbert in forum vb.announcements
    Replies: 0
    Last Post: 08-19-2001, 11:34 AM
  4. Replies: 2
    Last Post: 06-29-2001, 09:17 AM
  5. Ted, you're a prince!
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center