Papermashup

Subscribe


Tweets


"RT @cpray86: Good to see the receptionist's Jpeg of an Excel file is coming along nicely... #TheApprentice https://t.co/uiPGhf64U3"

@ashleyford 1 day ago

"Translation wrong for this paper it should be: Bitte nicht den Horror-Clown (Please not the Horror-clown) https://t.co/RYOD6aND6s via @bandt"

@ashleyford 3 weeks ago

Electrical Engineer/ Co-founder at Premium Planners

Papermashup

Dynamic alerts using JavaScript

Introduction to JavaScript - A simple JavaScript method to display multiple kinds of dialog boxes

Rachel AveryRachel Avery

Let’s talk about JavaScript and how it allows you to be able to pickup user input or display small amounts of text to the user by using popup dialog boxes. These dialog boxes appear as separate windows and their content depends on the information provided by the user. you can easily implement dialog boxes by using JavaScript and embedding it into your HTML code. To display line breaks inside a popup box you can use a back-slash followed by the character n.

There are two methods to embed dynamic box JavaScript into HTML code. You can either try Internal script method and directly write JavaScript into HTML code but practically I would recommend External script method which means you have to write your JavaScript in a separate file and call it in your HTML code. External Scripts are useful when you have lengthy scripts plus they improve the readability. JavaScript has three kind of popup dialog boxes

  1. Alert Dialog Box
  2. Prompt Dialog Box
  3. Confirm Dialog Box

Alert Dialog Box

An alert box, as many of you know is simply a small message box that pops up and gives the user some information like warning message.

The JavaScript Alert dialog box is the simplest of the three popup dialog boxes. You can use it on your website to give user some information like a warning message. It can also help you with debugging JavaScript scripts. You can place it in line with the script you are developing and use it to display the value of variables.

The Code


	function alertme()															  //  Start of the function
	{
		var message = document.getElementById("myalertbox").value;
		alert(message);																       //  Display's an alert box
	}


      

Prompt Dialog Box

If you want your user to input a value before entering a page on your website, JavaScript prompt is a perfect choice for you. It is the most complex of the three JavaScript popup dialog boxes. You will have to pass two arguments and in return you’ll get two different classes of response.


      function promptMe(){
          var name=prompt("please Enter Your Name","Name");
          document.write("Hello Mr. " + name);
      }
      promptMe();

Confirm Dialog Box

In a sense, the JavaScript Confirm dialog box is similar to an Alert dialog box because it accepts one argument but instead of just an ‘OK’ input, it has both an ‘OK’ input and a ‘cancel’ input.


	function conName(){
		var name=prompt("Your Name please!");	//  User input
		if(confirm("Write on the webpage ?"))	//  Confirmation
		{
			document.write("Welcome Mr." + name);
		}else{
			document.write("Welcome Mr. Anonymous"); //  Not confirmed
		}
	}
        conName();

Electrical Engineer/ Co-founder at Premium Planners

    Comments 0
    There are currently no comments.