Jump to content

Recommended Posts

Hi,

 

Im a newbee in ajax, and I find a script for a "live" check is some numbers available in database. Mean, when a typing a numbers in form they tell me is that number is in database or not. The problem is that I have a 2 or more forms, and I must to check each other separately. here is the script that I have, and I dont know how can I do that?

 

JS script:

 

var xmlhttp

 

function showHint(str)

{

        if (str.length==0)

        {

                  document.getElementById("message1").innerHTML="";

                  return;

        }

        xmlhttp=GetXmlHttpObject();

        if (xmlhttp==null)

        {

                  alert ("Your browser does not support XMLHTTP!");

                  return;

        }

        var url="JavaSript/check_nr/check_f_sifra.php";

        url=url+"?q="+str;

        url=url+"&sid="+Math.random();

        xmlhttp.onreadystatechange=showMessage;

        xmlhttp.open("GET",url,true);

        xmlhttp.send(null);

}

 

 

function showMessage()

{

        if (xmlhttp.readyState==4)

        {

                  document.getElementById("message1").innerHTML=xmlhttp.responseText;

        }

}

 

 

function GetXmlHttpObject()

{

        if (window.XMLHttpRequest)

        {

          // code for IE7+, Firefox, Chrome, Opera, Safari

                  return new XMLHttpRequest();

        }

        if (window.ActiveXObject)

        {

          // code for IE6, IE5

                  return new ActiveXObject("Microsoft.XMLHTTP");

        }

        return null;

}

 

 

here is a PHP script (check_f_sifra.php):

 

//get the q parameter from URL

$q = $_GET['q'];

 

//lookup all hints from array if length of q>0

if (strlen($q) >= 2) {

$getid = mysql_query("SELECT * FROM `farm` WHERE `farm_sifrafc` = '$q'");

$getid_row = mysql_num_rows($getid);

if($getid_row > 0) {

$response = '<img src="Media/aviable_NOT_icon.gif" alt="not aviable">';

} else {

$response = '<img src="Media/aviable_icon.gif" alt="aviable">';

}

}

//output the response

echo $response;

 

So in xhtml file is look like this:

<div class="RightContainer"><input type="text" id="SifraFC" name="farm_sifrafc" value="<?php echo $_POST['farm_sifrafc'];?>" onkeyup="showHint(this.value)" maxlength="10" class="SifraFC" /><div id="message1" class="sifraOK"></div></div>

 

I want to check another form (input) in the same file....

 

T

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/243478-check-aviability-from-database/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.