During the previous week I learnt form validation in Ajax . It was a very interesting process. There is a advantage in Ajax form validation, because the validation is completed without page reloading. Here the Ajax Code:-

function showHint(){
var subject = document.getElementById(“txt1″).value;
if (subject.length == 0)
{
document.getElementById(“txtHint”).innerHTML = “”;
return;
}
var selected_selPlans = document.form1.selPlans.selectedIndex;
var selected_value = document.form1.selPlans.options[selected_selPlans].value;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,”gethint2.php?q=”+subject+”&r=”+selected_value,true);
xmlhttp.send();
}

I also learnt how to retrieve the multiple checkbox values in which input names are the same.It is very easy to get single checkbox value. The Javascript code is as follows :-

var Plan = “”;
for (var i=0; i < document.myform.plan.length; i++)
{
if (document.myform.plan[i].checked == true)
{
Plan=Plan+" "+ document.myform.plan[i].value;
}
}

It was very interesting for me to create a table of two column which displayed the from database. The code is very simple :-

ini_set('display_errors',1);
$con = mysql_connect("192.168.1.100","codez","codez123");
$database = mysql_select_db("dealer_db",$con);
$dirStateInput = $_GET['msg'];
$query = "SELECT * FROM dealerdetails WHERE state LIKE '".$dirStateInput."'";
$result = mysql_query($query,$con);
$num = mysql_num_rows($result);
$x = 1;
$output = "";
?>


while($dirDealDetList = mysql_fetch_array($result)){//Display two column records
if($x%2 == 0){

$output .= " “.$dirDealDetList['DealerName'].”
“.$dirDealDetList['Address'].”
“.$dirDealDetList['Phone1'].”
“.$dirDealDetList['Phone2'].”
“.$dirDealDetList['Phone3'].”
“.$dirDealDetList['Mobile1'].”

“; //for even records
}else{
$output .= “
“.$dirDealDetList['DealerName'].”
“.$dirDealDetList['Address'].”
“.$dirDealDetList['Phone1'].”
“.$dirDealDetList['Phone2'].”
“.$dirDealDetList['Phone3'].”
“.$dirDealDetList['Mobile1'].”

“; // for odd records
}
$x++;
}
if($num%2 != 0)$output .= “”;//for blank td
echo “

“.$output.”

“;
?>

Latest posts by Sahel Aktar

  • Share/Bookmark