Saturday, 31 December 2011

Introducing AJAX with a simple example program

Hi Friends,
   Today I am going to discuss little AJAX.AJAX means Asynchronous Javascript
.   AJAX is used to send data to server and receive data from server without
reflect in the screen.Basically HTML pages are static and the are precomposed
by the server. So any change in any part of the page requires the entire page to be reloaded.
But using AJAX we can change only the required part of the page without reload the entire page.

       Ajax is not a programming language.This is only a programming technique.We use javascript to call Ajax functions.
javascript simply makes an object of  XMLHttpRequest  class of Ajax.Then call the open() method.The result will be the part  of page will be reloaded.

I am here introducing a simple example to understand the concept more clearly:

This is a web page have a text and three buttons named RED,GREEN,BLUE.
in the start the text is black.When click in red button the text color changed to Red.When click in Green button
the text color change to green if click in Blue button the text will be displayed in blue colour.The think to be noted that the
page never reloaded fully.But only the required part is reloaded.

I am including some sample screen shots.

There have two pages


<script type="text/javascript">

function func(opt)
   var xmlhttp;
  if (window.XMLHttpRequest)
     {       // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();

  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
<div id="target">
<h1>You can change my colour</h1>
<input type="button" value="Red" onclick="func(1)">

<input type="button" value="Green" onclick="func(2)">

<input type="button" value="Blue" onclick="func(3)">



case 1:
echo "<h1 style=\"color:red\">You can change my colour</h1>";

case 2:
echo "<h1 style=\"color:green\">You can change my colour</h1>";

case 3:
echo "<h1 style=\"color:blue\">You can change my colour</h1>";

Code Description

First go through index.html

Do you notice the three buttons.The onclick event of each button calls the javascript
function func()
.Each button call the func() with different parameter 1,2,3.
      The javascript function func() is defined in the <head> section.
      var xmlhttp; is the first step.We just declare a variable named xmlhttp.

Next step is xmlhttp=new XMLHttpRequest();.
that is initialise xmlhttp  XMLHttpRequest() with class.
But in Internet explorer5 and 6 the class is little different.Because it uses ActiveX
object to call Ajax.That is determined with the if statement in the code.

Next one is a nested function  xmlhttp.onreadystatechange=function().  In this function check for the status of the page.
document.getElementById("target").innerHTML=xmlhttp.responseText; this statement sets the innerHTML     property of       element target into the responseText or the return text.Please not that
the id of div in the html page is 'target'.

      Next is the core of Ajax,the open() method,"GET","msg.php?opt="+opt,true);
In the open method there have three parameters.

1.  GET    it describes the request is send as GET or POST.GET have a limitation in send parameters.
But GET is enough in this situation.Use post when handle large amount of data.

2.  he second parameter "msg.php" is the name of the php page to which data is send and receive the HTML.
The parameter opt is also send to the php page.The opt is the parameter send to the javascript
function by the HTML page.

3.  Next parameter is true.It specifies the data is send synchronously or
asynchronously.Our purpose is asynchronous so set this parameter always true.

Next is send() method 

When call this method the request is send to server.

Let's go through   msg.php
The parameter(opt) passed to msg.php is retrived to the variable $opt like this $opt=$_GET["opt"];
Then give this parameter to a switch and according to the value of opt
the color of text is changed.Style parameter is used for change the text color.

The output HTML generated by this page is send to the previous HTML page(index.html) and
it is displayed in the <div> block of index.php through innerHTML property of javascript.

Hope that this post is helpful to you.
I will come with more AJAX Tutorials in coming posts.

By Sukesh B R

Thursday, 29 December 2011

Shut down or Restart Windows using Visual Basic 6

Hi friends now I am discuss about restart or shut down windows XP or higher versions using Visual Basic 6.
Usually we use start menu then the shutdown button to  shut down.
But we can use the shell functions in VB 6 to shut down windows.

It is a single step statement:

Shell ("shutdown.exe -s -t 00")

Where shell() is the library function.
shell have three parameters,
shutdown.exe is a system program run on windows

-s specify the operation to be executed such as shut down/restart.
-s for Shut down,-r for Restart and -l for Log off.

The third parameter -t 00 specifies the time delay taken before the operation execute.
-t 00 specifies wait for 0 seconds,where -t 30 means wait 30 seconds before shut down.

  The scope of this function is very large.
For instance, we can make a vb form in which the shell function  Shell ("shutdown.exe -s -t 00")
is added in the form load event.Then make the project.exe.Then made a short cut icon to this .exe
file in desktop.In short cut icons properties set it's short cut keys to 'ctrl+alt+s'.Then press
these keys the computer will shut down in no time without asking anything.You can use this application to
shut down computer when you have no time to click start->Turn off computer->Turn off.

Hope that this post is helpful to you.
By Sukesh B R

Saturday, 10 December 2011

HTML event occur when focus of control loses

Hi Friends now I am discuss about onblur event in HTML.Onblur event is triggered
when selection of a control like text box or button loses
.Onblur can used to call a javascript function which do a specific task such as validation/case change.

I am here including a sample program.

<script type="text/javascript">
function Casechange()
var name=document.getElementById("txtname").value

Enter your name: <input type="text" id="txtname" onblur="Casechange()">


This program will convert the name entered in the name text box into upper case.
Hope that this post is usefull to you.
Thanks By Sukesh

Sunday, 4 December 2011

Play wav file using HTML

Here I am discuss about playing an audio file with HTML.For flexibility I am only introducing   play wav files.

You can see a demo here :-

The html code:
<audio controls="controls" autoplay="auto play">
<source src="ringin.wav" type="audio/wav">

The core of this code is <audio> tag.The 'controls' attribute is to display audio controls such as play/pause
button and mute button.If we don't include this tag the browser play
the wav file but there will be nothing displayed in the screen.
'autoplay' attribute specifies whether the audio file is play when load the page.If 'autoplay' doesn't set the audio file will not play since
the play button clicked.
   The <source> tag is used to specify the file to be played.'src' attribute is specify the wav file to be played.If the file is in the same location
as the html page we need to specify the name,otherwise the files location too.
The 'type' attribute is used to specify the type of audio file ,here 'audio/wav'.

I will be explain play a video using HTML in a coming post.
Hope that this post will be helpful to you.
By Sukesh B R.

Thursday, 1 December 2011

Show a web site icon besides the website URL

Here I am discussing show an icon in the browsers address bar beside the site URL.
You just add this code to your head section of the html page.

<link rel="shortcut icon" href="icon_name.ico">
<h1>Did you notice MSN icon is present in your address bar!!!!!</h1>

where 'icon_name.ico' is the name of the icon to be displayed.
This code works if the icon file exist in the same location of the html file.If this icon
is in a different location we must specify the location like

I am including a sample screen shot :

Hope that this post will be helpful to you.
With thanks Sukesh B R

Wednesday, 30 November 2011

Implementing Mouse in Turbo c

Hi friends,
Here I am describing the implementation of mouse in Turbo c compiler.
Turbo c is an old c compiler works based on  Dos operating System.It works
in the text mode.But have little graphical functions.
   Now Turbo C is not using widely,because of it's poor graphical performance and
dos based working.But for students who learn c programming Turbo c is the better choice.
Here is a sample program which implement mouse and handle it well.

int86() is the core function using to implement mouse.It is defined in header file 'dos.h'.

union REGS in,out;
  void restrictmouse()

     void showmouse()

void main()
printf("Left button clicked");
printf("Right button clicked");
printf("Middle button clicked");

REGS is an union predefined in Turbo c library.We declare two variables
of REGS type.It defines so many member variables. defines which opration to be done by mouse.
For instance if and call int86(0x33,&in,&out) the meanig is
show mouse pointer.
if Detect mouse Show mouse video Get x and y cordinates of mouse pointer and button clicked in out.
That is
Button clicked is : out.x.bx

if it mean hide mouse
7&8 for restrict mouse pointer,Restric mouse is means that define the
area in which the mouse pointer will be displayed.
7 is for restrict in x direction and 8 for y direction.;;
will restrict the mouse to all 640 pixels in x direction.;
will restrict the mouse to all 480 pixels in y direction.

Hope that this post will be helpful to you.Continue reading, the coming
post will be more helpful.  Thanks by Sukesh B R

Tuesday, 29 November 2011

Change font size of text in HTML page dynamically using php

Here I am discussing about dynamic changes that can be occur in HTML page.
In desk top applications like Visual Basic , we can easily change the font size of a label by clicking
a button if we programed like so.We does not worry about the background processes.
       But in the case of web the html page to be displayed to the user is send by the server.
The user's browser receives thi page and display it.But the server or php running in it can't make any changes to the page which is already
send.So a program which change the font of a text according to button click is not easily possible in php .But javascript can be used to do this.
      Here I am introducing a different trick in which the font size is send as a parameter in URL to the same page.This is just like in my previous post
 "Varying number of text boxes in HTML form by user".

The code is here :

<?php $n=$_GET["num"]; ?>
<label style="color: BLUE; font-size: <?php echo $n ?>pt">You can Increase or Decrease me</label>

echo "<a href=\"font.php?num=$ni\"><input type=\"button\" value=\"Increase\"> </a>";
echo "<a href=\"font.php?num=$nd\"><input type=\"button\" value=\"Decrease\"> </a>";

A sample screen shot of the resulting page

One thing to be remember is that the name of html page must be "font.php"

You can also read  Pass parameter to another page in PHP
Varying number of text boxes in HTML form  by user in PHP 

Hope that this post is helpful to you.Thanks...

Sunday, 27 November 2011

Varying number of text boxes in HTML form by user

Here I am introducing Variable number of text boxes in HTML form.That is a HTML form in which user can add any number of text boxes as options using PHP.Users can also remove added text box if required.


        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <table  width="100%" height="100%" align="center">
            <tr><td colspan="4">
        <form name="q_form" action="question_submit.php" method="post">
<tr height="100">    <td>   Question</td><td colspan="3"><textarea input  rows="4" cols="79" name="question"></textarea></td></tr>
<?php $n=$_GET["num"];

   echo "<tr height=\"50\" ><td>Option $i</td><td><input type=\"text\" name=\"$i\" size=\"58\"></td>";

echo "<tr><td>";
  echo" <a href=\"question.php?num=$na\">Add</a>";
echo "<a href=\"question.php?num=$nr\">Remove</a>";
  echo "</tr></td>";

    <tr align="center"><td colspan="4" align="center" height="75">    <input type="submit" value="Submit" ></td></tr>


The resulting HTML page will be look like above.

Here I am using URL to pass the number of text boxes required like this
  echo" <a href=\"question.php?num=$na\">Add</a>";
echo "<a href=\"question.php?num=$nr\">Remove</a>";

the value passed by $na or $nr is in num parameter of URL.It will be like this
This 'num' parameter is parsed into $n variable using php like this ,
That is the value we send directly to the URL is treated as form submitted using get method.

Then using a loop display '$n' number of text boxes in the page.
Then execute this code 

here $na increased by one than $n
but $nr decreased by one than $n.

Then gives to links Add,Remove
echo" <a href=\"question.php?num=$na\">Add</a>";
echo "<a href=\"question.php?num=$nr\">Remove</a>";

That is if user click 'Add' link the 'num' parameter in the URL will be increased by one than the current page.
If  user click 'Remove' link the 'num' parameter in the URL will be decreased by one than the current page.

Thus it will give a flexible page,in which user can add/remove any number of option fields.

One important thing to note that in the first time page is loaded there will be no option text boxes because
the 'num' parameter in URL will be zero.
We can tolerate by call this page URL from another link and put 'num'
as 2.

That is in a new html page type like this
<a href="answer.php?num=2">Click to next Page </a>

Where answer.php is the name of html page we created earlier.

You can also see another example like this :-  Change font size of text in HTML page dynamically using php

Hope that this post will be helpful to you.  Thanks... 

Saturday, 26 November 2011

Introducing the concept of for loop to beginers

Here i am introducing the logical side of loops.Here I am considering for loop.Coding is in ANSI C standard.

It is mainly for beginers who entering in programing world.

1)printf("#"); displays a # in the screen.

2) for(i=1;i<=4;i++)
it will display : # # # #

3) If we want to display like this
# # # #
# # # #
# # # #
# # # #

we can use two for loops one is nested in other,


'\n' is used to print in the next line or new line.

4) For display like this :-
# #
# # #
# # # #


5) For display like this :-

# # # #
# # #
# #


I hope that the post will be helpful to you.Thanks...

Friday, 25 November 2011

Swap or Interchange two varibles without using a third variable

I am revealing Swaping two variables without using a third variable.
For readability I am using ANSI C format for coding ,You can use it in any language.

Now a=10 and b=5.

But in traditional programing logic it will be
Here using a third variable.It is not a good programming concept.

newprogaminglogics is for introducing new programing logics

The purpose of this blog is introducing  new programing logic for programmers.I will try to solve each and every tricks in programming in a new way,which will be simple.I hope that this will be helpful to not only beginers  but also professionals in programing field.My posts will cover the concepts in C,C++,Visual Basic,C#.Net,java,PHP,Javascript,CSS,WebDesign etc.Please follow my posts.  

Search This Blog