Searching...
Wednesday 3 October 2012

Java Script Dialog Box

10:55 pm

Java Script Dialog Box

Java Script Dialog Box :

1.       Message dialog box :

Alert(message)

2.       Confirmation dialogbox:

Confirm(message)   : returns a boolean value

3.       Input dialog box :

Prompt(message,default value) : returns a string or null

Example Program : Dialog boxes:

     <html>
     <head>
   <style  type=”text/css”>
   #name
   {
    Font-family: verdana;
    Font-size: 20px;
   Margin-left : 400;
  Margin-right:200;
  Height : 50;
  Background-color:cyan;
  }
  </style>
   <script type=”text/javascript”>
     Function fun1()
     {
     Alert(“this is a message box”);
     }
     Function fun2()
     {
      Var b= confirm(“do you want to close the app”);
  If(b)
    Window.close();
   }
    Function fun3()
    {
      Var s =prompt(“enter ur name”,”india”);
      If(s==null)
      {
       S=”enter data and click ok”;
      }
     Document.getElementById(“name”).inner.HTML=s;
     Document.getElementById(“name”).style.color=red;
      }
      </script>
      </head>
      <body>
      <button onclick=”fun1()”> message dialog box</button>
      <button onclick=”fun2()”> confirm dialog box</button>
     <div id=”name”></div>
     </body>
    </html>

Example 2:

      <html>
     <head>
    <style type=”text/css”>
    #div1
    {
      Visibility : hidden;
    }
   </style>
    <script type=”text/javascript”>
     Function fun()
   {
    If(document.getElementById(“b1”).value==”show”)
   {
     Document.getElementById(“b1”).value =”hide”;
    Document.getElementById(“div1”).style.visibility=”visible”;
  }
  Else
   {
    Document.getElementById(“b1’).value=”show”;
   Dcoument.getElementById(“div1”).value=”hidden”;
    }
   }
  </script>
  </head>
 <body>
   <input type=”button” id =”b1” value=”show” onclick=”fun()”>
   <br><br>
   <div id=”div1”>
   <img src=”path”   width=”200”  height=”200”  align=”right”>
        </div>
      </body>
    </html>

1 comments:

  1. Hi, thanks for posting a tips-full article, I had learned more things on this blog, Keep on blogging, thanks .
    JAVA Training in chennai

    ReplyDelete