Thursday, February 23, 2012

Case implementation in VBScript


Case in VB script program.(Only IE)

 When form will load into browser window the onload event will call greeting() function .




<html>
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/vbscript">
Function greeting()

d=weekday(date)
Select Case d
  Case 1
    document.write("Sleepy Sunday")
  Case 2
    document.write("Monday again!")
  Case 3
    document.write("Just Tuesday!")
  Case 4
    document.write("Wednesday!")
  Case 5
    document.write("Thursday...")
  Case 6
    document.write("Finally Friday!")
  Case else
    document.write("Super Saturday!!!!")
End Select

End Function
</script>
   
</head>
<body onload="greeting()">
    <form id="form1" runat="server">
    <div>


  
    </div>
    </form>
</body>
</html>

Function in VBScript language


VB script function is very similar with VB and JavaScript function. The function will call when the form will load into browser window.



<html>
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/vbscript">
Function greeting()
i=hour(time)
If i < 10 Then
  document.write("Good morning!")
Else
  document.write("Have a nice day!")
End If
End Function
</script>
   
</head>
<body onload="greeting()">
    <form id="form1" runat="server">
    <div>
  
    </div>
    </form>
</body>
</html>

Prompt window using VB Script


VB script is a client side programming language. VB script is introduced by Microsoft .And only Microsoft web browser Internet Explorer support it. It is very similar with JavaScript which was introduced by Netscape navigator. VB script is not so popular as javaScript because of it’s narrow browser support.
You can place VBScript program in body and head section both.


This program will open a pop up window in browser


<html>
<head>
<script type="text/vbscript">
function myFunction()
   alert("Hello World!")
end function
</script>
</head>

<body>
<button onclick="myFunction()">Click me</button>
<script type="text/vbscript">
document.write("This message is written by VBScript")
</script>
</body>
</html>

Wednesday, February 22, 2012

Develop pole(Like facebook vote) application using PHP and AJAX


This program is for develop poll application using AJAX ,JSON and PHP . Copy and paste following file to develop poll application . Use Internet Explorer to view the output .In other browser it may not work.

Step 1) Copy and paste below code in your PHP file.


Output:-



Databse table structure:-








<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript">
function ajax(val)
{

var result=val;
var xmlhttp=new XMLHttpRequest();

 if(xmlhttp=="")
   {
     alert("Object not created");
   }
  else
  {
                //ajax object creaTED.......
    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
       {
                                 //var result = xmlhttp.responseText;
                                 //document.getElementById("myp").innerHTML=result;
                                 
                                 var jsonText = xmlhttp.responseText;
                                 var jsonObject= eval('('+jsonText+')');
                                 
                                 var yes=jsonObject.yes;
                                 var no=jsonObject.no;

                                 document.getElementById("mypicyes").width=yes;
                                 document.getElementById("mypicno").width=no;

                                 document.getElementById("yes").innerHTML=yes-1;
                                 document.getElementById("no").innerHTML=no;
                                 
                                                                                 
       }
    }
   xmlhttp.open("GET","pollvote.php?vote=" + result,true);
   xmlhttp.send();

  }
}

</script>
<title>AJAX testing page.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<center><h1>Poll your vote here.</h1></center>

<table>
 <tr>
   <td>Yes:</td>
   <td><img id="mypicyes" src="bg.jpg" height="20px"></td>
   <td><p id="yes"></p></td>
 </tr>
 <tr>
 <td>No:</td>
 <td><img id="mypicno" src="bg.jpg" height="20"></td>
 <td><p id="no"></td>
 </tr>
</table>             
<form name="myform">
<p id="myp"></p>
Select your vote :-<br>
PHP or ASP.Net
<input type="radio" name="radiovote" value="1" onClick="ajax(this.value)">ASP.Net
<input type="radio" name="radiovote" value="0" onClick="ajax(this.value)">PHP
</form>
</body>
</html>


Step 2) Copy the image into same location of your server directory.

Step 3)  Paste below code and edit database connection and table information part. In my table information having following column.
·         Id
·         Yes
·         No


<?php
$val=$vote;

$conn=mysql_connect("localhost","root","");
if($conn==NULL)
  echo "Database connection failure";
 
$db=mysql_select_db("ajax",$conn);
if($db==NULL)
  echo "Database selection failure";
   
if($val==1)
  {
     $qur="select * from vote";
                 $ans=mysql_query($qur);
                 while($row=mysql_fetch_array($ans))
                 {
                    $val=$row['yes'];
                 }
                 $nval=$val + 1;
                 $qur="UPDATE `ajax`.`vote` SET `yes` = '$nval' WHERE `vote`.`id` =1";
                 $ans=mysql_query($qur);
  }
  else
  {
                 $qur="select * from vote";
                 $ans=mysql_query($qur);
                 while($row=mysql_fetch_array($ans))
                 {
                    $val=$row['no'];
                 }
                 $nval=$val + 1;
                 $qur="UPDATE `ajax`.`vote` SET `no` = '$nval' WHERE `vote`.`id` =1";
                 $ans=mysql_query($qur);

  }
 
$qur="select * from vote where id=1"; 
$ans=mysql_query($qur);

while($row=mysql_fetch_array($ans))
{
   $yes= $row['yes'];
   $no= $row['no'];

}
 
     $qur="select * from vote";
                 $ans=mysql_query($qur);
                 while($row=mysql_fetch_array($ans))
                 {
                    $valyes=$row['yes'];
                                $valno=$row['no'];
                 }
                 $total = $valyes + $valno;    
                 $yespercent=ceil(($valyes / $total)* 100);
                 $nopercent=ceil(($valno / $total)* 100);
//Json data creation goes here.
  $ans=Array("yes" => $yespercent,"no" => $nopercent);
  $json_name=json_encode($ans);
  echo $json_name;    //Data is returning main page here
 ?>