views:

39

answers:

2

dear all..i have a textfield. i want after i have typed identity number inside it, the script can identifying to "user table" at DB. i want if id number not match can show an alert.. how do i do that?i'm newbie at javascript

A: 

Your JS code should be something like this:

var identityNum = 'xxxxx'; // ajdust value / fetch from db
var val = document.getElementById('input-field-id').value;

if (val === identityNum)
{
  // success... your further code
}
else
{
   alert('No match found !!');
}
Sarfraz
A: 

so basicly you can split up your problem in two parts:

  1. on the change of your identity field check the user id

    $('input#userid').change(function(){ checkUserId( $(this).val() ); });
    
  2. by checking the database

    function checkUserId( id ){
        $.ajax({
            type: 'POST', // or get
            url: 'some_url.php',
            data: {userid:id},
            success: function(data){
                if(data == 'false') alert('Wrong user id');
            }
        });
    }
    

    someting like that