Tuesday, August 14, 2012

Javascript Module 11

Javascript Popup Boxes
Javascript မွာ Popup box သံုးခုရွိပါတယ္
အဲဒါေတြကေတာ႔
1. Alert box
2. Comfirm box
3. Prompt box တို႔ပဲ႔ျဖစ္ပါတယ္

1. Alert box အေၾကာင္း
user ေတြနဲ႔ပတ္သက္ျပီး information ေတြကိုေသခ်ာေအာင္ ျပဳလုပ္ဖို႔ မၾကာခဏ alert box ကိုအသံုးျပဳၾကပါတယ္
pop up ဆိုတဲ႔ alert box ေလးတက္လာတဲ႔ အခါမွာေတာ႔  user က ok ကိုႏွိပ္လိုက္တာနဲ႔ process လုပ္ရမွာပါ

Syntax
alert ( " Your text here " );

ဥပမာ
<html>
<head>
<script type="text/javascript">
function alertbox()
{
alert("I am alert box");
}
</script>
</head>
<body>
<input type="button" onclick="alertbox()" value="Click me"/>
</body>
</html>

2. Comfirm Box
data ေတြကိုလက္ခံဖို႔ ဒါမဟုတ္ user ေတြကို verify လုပ္ေစခ်င္တဲ႔အခါမွာေတာ႔ confirm box ကိုမၾကာခဏအသံုးျပဳၾကပါတယ္
confirm box pops up တက္လာတဲ႔အခါမွာေတာ႔ user က ok နဲ႔ cancel နွစ္ခုထဲ႔က ၾကိဳက္ရာတစ္ခုကို ေရြးျပီး process လုပ္ပါတယ္
user က ok ကို click လုပ္တယ္ဆိုရင္ေတာ႔ pops up box က  true လို႔ return ျပန္မွာျဖစ္ျပီး
တစ္ကယ္လို႔ cancle ကိုနွိပ္ရင္ေတာ႔ false လို႔ return ျပန္ပါတယ္

Syntax
confirm("Your Text");

ဥပမာ
<html>
<head>
<script type="text/javascript">
function confirm_box()
{
    var confirm_box= confirm("Do you know cyberoot");
    if(confirm_box==true)
    {
        alert("You click ok");
    }
    else
    {
        alert("Why you Click Cancel");
    }
}
</script>
</head>
<body>
<input type="button" onclick="confirm_box()" value="Show Comfirm Box Message"/>
</body>
</html>

3. Prompt box
တစ္ကယ္လို႔ user ေတြကို page တစ္ခုထဲ႔ကို မ၀င္ခင္ value ေတြစစ္တဲ႔အခါမွေတာ႔ prompt box ကိုအသံုးျပဳပါတယ္
prompt up box တက္လာတဲ႔အခါေတာ႔  ok နွိပ္ျပီး user က process လုပ္ျပီး page ထဲကို၀င္မယ္ ဒါမွမဟုတ္ရင္
Cancle ကိုႏွိပ္ရင္ေတာ႔ input value ကိုမထည္႔ပဲ႔နဲ႔ process လုပ္သြားမွာျဖစ္ပါတယ္
user က ok နွိပ္ရင္ input value ကို return ျပန္ျပီး cancle နွိပ္ရင္ေတာ႔ null ကို return ျပန္မွာပါ

Syntax
prompt("sometext","defaultvalue");

ဥပမာ
<html>
<head>
<script type="text/javascript">
function prompt_box()
{
    var name=prompt("Pleae enter your name","cyberoot");
    if(name!=null && name!="")
    {
        document.write("Welcome ! " + name + " I love you");
    }
}
</script>
<body>
<input type="button" onclick="prompt_box()" value="Show Prompt box"/>
</body>
</html>

အဆင္ေျပပါေစ
Thanks for Reading..
Written by cyberoot1@gmail.com

No comments:

Post a Comment

Thanks for your comments
Welcome from cyberoot