Tutorials » Javascript tutorials »

prompt, confirm ,alert all together


This article explains usage of alert ,prompt,confirm


Let's put all together with some conditional statement in one example and proceed further.



<body>

<script type="text/javascript">

var v=window.prompt("Enter your rating from 1 to 10 scale in JavaScript");

confirm("Are you sure you want to see the rating");

if(v>5)
alert('Good');

else if(v==5)
alert('Moderate');

else
alert('Poor');


</script>

</body>



Here if is a conditional statement that checks value of v. If v is greater than 5 then an alert message is fired with message as Good.

If v is equals to 5 then corresponding message is fired.

Apart from above two cases for all the other a message box with message ‘Poor’ is displayed.

Note
Script tag can be placed in Header or body but if you want to place it in the body you need to mention language = JavaScript . But in header it’s an optional since it take JavaScript in Body by default

I think now you are confident enough on alert, confirm, prompt.

Let's move on to the next chapter then...




Next Chapter: Calling JavaScript function in an Event
Previous Chapter: Working with confirm and prompt
More Chapters: Javascript Tutorials
More Tutorials: Tutorial Index



Top Contributors
Today
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    More...
     
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India