condition may be relational expression or logical expression. First condition will be evaluated, if the condition returns true then the value of the left side of the colon is assigned to the variable otherwise the value of the right side of the colon will be assigned the variable. For example, var result=( > ) ? : ; In the above example, since the condition returns false the value will be assigned to result.
Chapter Pages <Html> <Head> <Title>Demo Program - To test Conditional Operator in JavaScript </Title> </Head> <Body> <script language="javascript" type="text/javascript"> var value1 = , value2= , value3; value3=(value1<value2) ? value1: value2; document.write("<br>The Value of Data1 = "+value3); </script> </Body> </Html> Illustration . Condtional Operator Output: . JavaScript Popup or Dialog Boxes: JavaScript supports three important types of dialog boxes.
Dialog boxes are also called as Popup Boxes. These dialog boxes can be used to raise an alert, or to get confirmation on any input or to have a kind of input from the users. JavaScript supports three kind of popup boxes: Alert box, Confirm box, and Prompt box. .
. Alert Dialog Box: An alert dialog box is mostly used to give a warning message to the users. For example, if one input field requires to enter some text but the user does not provide any input, then as a part of validation, you can use an alert box to give a warning message. Alert box gives only one button "OK" to select and proceed.
The syntax of alert box is Alert(“Message”); (or) Window.alert(“Message”); Example: alert(“Name is compulsory entry”); (or) window.alert(“Name is compulsory entry”); Chapter Pages <Html> <Head> <Title>Demo Program - To test Alert Dialog Box in JavaScript </Title> </Head> <Body> <script language="javascript" type="text/javascript"> var value1 = , value2= ; window.alert("Data1 : "+value1); alert(“Data1 :”+value2); </script> </Body> </Html> Illustration . Alert Dialog Box Output: . . Confirm Dialog Box: A confirmation dialog box is mostly used to take user's consent on any option.
It displays a dialog box with two buttons: OK and Cancel . If the user clicks