web_master Posted August 1, 2011 Share Posted August 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243478-check-aviability-from-database/ Share on other sites More sharing options...
sunfighter Posted August 2, 2011 Share Posted August 2, 2011 When you call your function showHint(str) use a different str for your second call. Change (add to) your php code to perform a second(different) query when the new $_GET['q'] arrives Quote Link to comment https://forums.phpfreaks.com/topic/243478-check-aviability-from-database/#findComment-1250902 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.