JavaScript utility popup boxes for better user interaction


JavaScript utility popup boxes for better user interaction:

 

  1. Alert Box – JavaScript pop up to display any information or error messages to the user.As JavaScript is a client side scripting language we can use this alert box to interact with the user.You can raise the alert message through some events or it can be used in debugging purpose.

    It can be used as a great debugging tool in Classic ASP or PHP or in large and complicated JavaScript.

    Image of Javascript Alert Popup box

    Javascript Alert Box

     

<HTML>

<HEAD>

<TITLE> Alert Test </TITLE>

<script type=”text/javascript”>

function showTheAlert(){

        alert(“Hi I have been called for”);

}

 

function showAlertWithMessage(msg){

        alert(“The message is : ” + msg );

}

 

</script>

</HEAD>

 

<BODY>

<h1>Simple Atert test</h1>

<input type=”button” name=”showAlert” onclick=”javascript:showTheAlert()”
value=”Show me the alert” />

 

<br/>

<h1>Custom alert with message</h1>

<input type=”text” name=”msgAlert” id=”msgAlert”/>

<input type=”button” name=”showMsgAlert” onclick=”javascript:showAlertWithMessage(document.getElementById(‘msgAlert’).value)” value=”Show me the alert” />

 

</BODY>

</HTML>

 

  1. Confirm Box: This is a very good JavaScript pop up box which confirms user action.Such as if you want the user to confirm his action like deletion of some important data this pop up box can be used. Image of Javascript confirm message box

    Jacascript Confirm Message box

     

<HTML>

<HEAD>

<TITLE> Confirm Test </TITLE>

<script type=”text/javascript”>

function ConfirmTest(){

        var conf = confirm(“Are you sure want to Perform this action ??”);

 

        if(true == conf){

                alert(“You have pressed the YES button”);

        }else{

                alert(“You have pressed the CANCEL button”);

        }

}

 

</script>

</HEAD>

 

<BODY>

<br/>

<h1>Confirm pop up box test</h1>

<input type=”button” name=”confrmBtn” onclick=”javascript:ConfirmTest()” value=”Show me the alert” />

</BODY>

</HTML>

  

  1. Prompt Box: This box is very useful if you want the user to input some text at the runtime or as a result of some action.Suppose you may want the user to enter his transaction password if he is performing some important action.Then this Prompt popup box may come handy.

    Notation of prompt is:

    prompt(“Your message”, ”default value you want to display”);

    If you want to display some default values you can specify that also by setting the second argument of this popup box.

      

<HTML>

<HEAD>

<TITLE>Prompt for user input Test </TITLE>

<script type=”text/javascript”>

function PromptTest(){

        var age = prompt(“Enter your age”,”99″);

       

        if(null != age && age != “undefined”){  

                alert(“Your age is: ” + age);

    }else{

                alert(“You have pressed the CANCEL button dear”);

    }

}

 

</script>

</HEAD>

 

<BODY>

<br/>

<h1>Prompt pop up box test</h1>

<h3>Click this button to enter your age </h3>

<input type=”button” name=”confrmBtn” onclick=”javascript:PromptTest()” value=”Show me the alert” />

 

</BODY>

</HTML>

 I think this popup boxes and the tutorial can help you to start exploring the technology of the web and JavaScript.

 Happy JavaScripting 🙂 

Advertisements

Parsing XML File in ASP


Hi If you need to parse a XML file in ASP Code you may use the following:

First we need a XML file named book.xml.

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<books>
<book>
<name>
<![CDATA[ ASP and AJAX  ]]>
  </name>
<description>
<![CDATA[ This is a book for ASP and AJAX ]]>
  </description>
<author>
<![CDATA[ Author 1 ]]>
  </author>
  </book>
<book>
<name>
<![CDATA[ XML ]]>
  </name>
<description>
<![CDATA[This book is for XML learning  ]]>
  </description>
<author>
<![CDATA[ Author 2 ]]>
  </author>
  </book>
  </books>
  </configuration>
Now create a ASP file to parse this XML.
<%
‘Set the XML Object
 

Set objXML = Server.CreateObject(“Microsoft.XMLDOM”)

‘Set Asynchoronous = false
objXML.async = False

‘Load the XML file.
‘User Server.MapPath method is the XML is located in your site.
‘Else you can use the absolute path.

objXML.Load (Server.MapPath(“db/book.xml”))

‘If there is any errors pasring the file the notify

If objXML.parseError.errorCode 0 Then

Response.Write “Error Parsing XML”

Response.Write  “Rason :” & objXML.parseError.reason & “Error Line: ” & objXML.parseError.line

End If

‘Get ALL the Elements by the tag name book

Set books = objXML.getElementsByTagName(“book”)

‘Now Iterate through the List and Display

 For i = 0 to (books.Length-1)
    Response.Write “Name: ” & books.item(i).childNodes(0).text  & “<br/>”
    Response.Write “Description: ” & books.item(i).childNodes(1).text & “<br/>”
    Response.Write “Author: ” & books.item(i).childNodes(2).text & “<br/>”
Next
%>

Bingo 😉