know yourselves. information, computer, 7 wonders, various.

Saturday, March 7, 2020

JavaScript_part8_Continue Statement, জাভাস্ক্রিপ্ট অ্যালার্ট বক্স ও প্রম্পট বক্স



Continue Statement
মূল কথা হল Continue স্টেটমেন্টটি বর্তমান লুপটিকে ছেড়ে পরবর্তী লুপ থেকে আবার একই রকম কাজ করতে থাকবে।
প্রোগ্রামঃ  Continue Statement ব্যবহার
১।        আপনার এডিটরে নিচের কোডিং এর মত করে প্রোগ্রাম লিখুন
২।   এবার ফাইলটিকে কে একটি নির্দিষ্ট  নামে  সেভ করুন। আমরা এখানে program_0033.html নামে সেভ করেছি
<html>
<head>
<title>While Example</title>
<script type="text/JavaScript">
function CalculateSum()
{
var number=document.getElementById("txtNumber").value;
number=parseInt(number);
var i;
var sum=0;
for(i=1;i<=number;i++)
{
if(i==5)
{
continue;
}
sum=sum+i;
}
alert(" The Summation of "+number+ " is = " +sum);
}
</script>
<head>
<body>
Input  Number: <input type="text" id="txtNumber" /><br />
<button onclick="CalculateSum();">OK</button>
</body>
</html>
ফলাফল :           ব্রাউজারে program_0033.html ফাইলটি ওপেন করুন। যে কোন ভ্যালু ইনপুট দিন।
ব্যাখ্যা:   প্রোগ্রামটি মূলত: ১ থেকে n পর্যন্তু যোগফলের প্রোগ্রাম। কিন্তু যত বারই আপনি যে কোন নাম্বার ইনপুট দিন না কেন মোট যোগফল থেকে 5 কম ফলাফল পাবেন। কারণ
if (i=5)
continue
}
এই স্টেটমেন্ট দ্বারা বুঝায় যে, 5তম লুপটি Cancel হবে আবার 6তম লুপ থেকে পুনরায় লুপ শুরু হবে।

জাভাস্ক্রিপ্ট পপ আপ বক্স
এই অংশে আমরা শিখব-
      জাভাস্ক্রিপ্ট অ্যালার্ট বক্স
       জাভাস্ক্রিপ্ট কনফার্ম বক্স
       জাভাস্ক্রিপ্ট প্রম্পট (Prompt) বক্স
জাভাস্ক্রিপ্ট  অ্যালার্ট (Alert) বক্স
জাভাস্ক্রিপ্ট আপনার ব্রাউজারে খুবই সহজে কোন Alert দিতে পারে । এক্ষেত্রে আপনাকে নিম্নের মত করে কোড  লিখতে হবে অর্থ্যাৎ Alert () ফাংশন ব্যবহার করতে হবে।
প্রোগ্রাম : Alert ()  উদাহরন
১।        আপনার এডিটরে নিম্নোক্ত কোডগুলো লিখুন।এবার ফাইলটিকে কে একটি নির্দিষ্ট  নামে  সেভ করুন। আমরা এখানে program_0034.html নামে সেভ করেছি
<!DOCTYPE html>
<html>
<body>
<head>
<title>
Alert Example
</title>
<script type="text/javascript">
function DisplayAlert()
{
alert("Hellow this is Alert Box")
}
</script>
</head>
<body>
<button type="button" onclick="DisplayAlert()">Display Alert </button>
</body>
</html>
ফলাফল :    এবার আপনার ব্রাউজারে program_0034.html ফাইলটি ওপেন করুন। নিম্নের চিত্রের মত ফলাফল দেখতে পাবেন।
ব্যাখ্যা: এখানে Alert ()  ফাংশনের মধ্যে আপনি যেকোন text value লিখতে পারেন যেটি Alert বক্সের  মাঝে দেখা যাবে। আমরা উপরোক্ত উদাহরনে একটি বাটন তৈরি করেছি এবং যার On click ইভেন্টে আমাদের Display Alert ()  নামের ফাংশনটি কল করা আছে। এর মানে  হল এই যে আপনি যখন Display Alert বাটনটিতে ক্লিক করবেন তখনই Alert দেখা যাবে।
এবার বাটনটিতে ক্লিক করম্নন নিমেণর চিত্রের মত Alert বক্স দেখা যাবে।
জাভাস্ক্রিপ্ট  অ্যালার্ট (Confirm) বক্স
যেকোন দুটো কাজের মধ্যে একটি করার জন্য Confirm () ব্যবহার করা হয়।

 Confirm ()  উদাহরন
১।        আপনার এডিটরে নিম্নোক্ত কোডগুলো লিখুন
২।       এবার ফাইলটিকে কে একটি নির্দিষ্ট  নামে  সেভ করুন। আমরা এখানে program_0035.html নামে সেভ করেছি  এখানে দেখতে পাবেন যে Confirm () ফাংশনের মাঝে “Are you sure??” এ কথাটি লিখা আছে।
<!DOCTYPE html>
<html>
<body>
<head>
<title>
Javascript Confirm Box
</title>
<script type="text/javascript">
function DisplayConfirm()
{
confirm("Are You Sure??")
}
</script>
</head>
<body>
<button type="button" onclick="DisplayConfirm()">Display Confirm</button>
</body>
</html>
ফলাফল :    এবার আপনার ব্রাউজারে program_0035.html ফাইলটি ওপেন করুন। নিম্নের চিত্রের মত ফলাফল দেখতে পাবেন। Display Confirm বাটনে ক্লিক করুন ।

এক্ষেত্রে ও Display বাটনের Onclick event Display Confirm ফাংশনটি কল করা আছে তাই Display Confirm বাটনে ক্লিক করলেই নিমেণর চিত্রের ন্যায় আউটপুট দেখতে পাবেন।
Confirm () মূলত দুটি ভ্যালু রিটান করে true বা false. ok বাটনে প্রেস করলে true হল নতুবা false হয়।চলুন নিচের প্রোগ্রামটি প্রাকটিস করা যাক

কনফার্ম বক্সের উদাহরণ:
১.        আপনার এডিটরে নিম্নোক্ত কোডগুলো লিখুন। এবার ফাইলটিকে কে একটি নির্দিষ্ট  নামে  সেভ করুন। আমরা এখানে program_0036.html নামে সেভ করেছি
<html>
<head> 
<title>Confirm Box Example</title>
<script type="text/JavaScript">
function ConfirmTest()
{
 var Con_Check=confirm("Are you sure to Enter Our Site");
 if(Con_Check==true)
 {
 window.open('http://www.novacomputerbd.com');
 }
 else
 {
 alert("You did Not Enter");
 }
 }
</script>
<head>
<body>
<button onclick="ConfirmTest();">Click Me</button> </body> </html>
ফলাফল :    এবার আপনার ব্রাউজারে program_0036.html ফাইলটি ওপেন করুন। নিম্নের চিত্রের মত ফলাফল দেখতে পাবেন।
৩.        এবার click me-তে ক্লিক করুন। দেখুন নিচের ছবির মত একটি কনফার্ম বক্স আসবে।
৪.        এবার আপনি OK বা Cancle বাটন প্রেস করুন।
OK বাটনে প্রেস করলে novacomputer লিংক ওপেন হবে কারণ জাভাস্ক্রিপ্ট ফাংশনটিতে con_check নামক একটি ভেরিয়েবল confirm( ) ফাংশনের রিটার্নকৃত ভ্যালু অ্যাসাইন করা হয়েছে। যেহেতু confirm( ) ফাংশন  true বা false রিটার্ন করবে। যদি OK বাটনে ক্লিক হয় তবে এটি true রিটার্ন করে। অন্যথায় false রিটার্ন করে। তাই, OK বাটনে ক্লিক করলে con_check ভেরিয়েবলে true অ্যাসাইন হবে। এবার if কন্ডিশন দ্বারা চেক করা হল এবং Windows Open ( ) ফাংশন ব্যবহার করে novacomputer.com এর লিংক ওপেন করা হল।WindowOpen( )  নতুন একটি উইন্ডো ওপেন করতে ব্যবহার করা হয়।
প্রম্পট (Prompt) বক্স
Prompt বক্স ব্যবহার করে আপনি যে কোন পেজ-এ প্রবেশের পূর্বে ভ্যালু ইনপুট দিতে পারেন।
যখন Prompt বক্স Pop-up হয় তখন ভ্যালু ইনপুট দিয়ে OK বা Cancel বাটনে ক্লিক করতে হয়। OK বাটনে ক্লিক করলে ঐ ভ্যালু নিয়ে কাজ করা যায় অর্থাৎ prompt বক্স ঐ ভ্যালু রিটার্ন করে।
আর Cancel বাটনে ক্লিক করলে prompt বক্স null রিটার্ন করে।
সিনট্যাক্স (Syntax)
prompt(“...” “default value”)

Confirm ()  উদাহরন

১.        আপনার এডিটরে নিম্নোক্ত কোডগুলো লিখুন। এবার ফাইলটিকে কে একটি নির্দিষ্ট  নামে  সেভ করুন। আমরা এখানে program_0037.html নামে সেভ করেছি
<html>
<head>
<title>Prompt Box Example</title>
<script type="text/JavaScript">
function PromptTest()
{
var x;
var name=prompt("Please enter your name","Bappi");
if (name!=null)
  {
  x="Hello " + name + "!";
  document.getElementById("txtName").value=x;
  }
}
</script>
<head>
<body>
<input type="text" id="txtName">
<button onclick="PromptTest();">Click Me</button>
</body>
</html>
ফলাফল :    এবার আপনার ব্রাউজারে program_0037.html ফাইলটি ওপেন করুন।
২.        Click me বাটনে ক্লিক করুন এবঙ দেখতে পাবেন যে prompt বক্সটি prompt নামসহ পপআপ হয়েছে।
৩.        এবার আপনি আপনার নাম লিখে OK বাটনে ক্লিক করুন।
 text বক্সে  নিম্নোক্ত ফলাফল দেখুন।
Previous Post                                                                                           Next Post

  বিস্তারিত জানতে নিচের বইটি সংগরহ করে নিন।

Book Name: Mastering Microsoft  Word
Writer: Bappi Ashraf
Published By: Gyankosh Prokashani
Amount of Pages: 464
First Publish: October-2004
Last Edition: We've February-2015 edition. Future edition may be existed!
Book Price: BDT 350 (30% Discount)
 The writer of this book has told that he has written this book with the concept of "teach yourself". On the other hand, Web Design is a thing which is interesting to learn. He has also told that the book is full of fan and enjoyment so that a person can learn Web Design by himself by playing with the example projects of this book.  Book's CD Link below... 

 cd

RELATED POST LINKS BELOW ********************************************

Friday, March 6, 2020

JavaScript_part14_জাভাস্ক্রিপ্ট ডেট (Date) অবজেক্ট ও মেথডের উদাহরন




জাভাস্ক্রিপ্ট ডেট (Date) অবজেক্ট
জাভাস্ক্রিপ্ট এ সময় এবং তারিখ নিয়ে কোন কাজ করতে হলে অবজেক্ট ব্যবহার করতে হবে। ডেট কনস্ট্রাকটর Date ( ) এর মাধ্যেমে ডেট অবজেক্ট তৈরি করতে হবে। ডেট অবজেক্টকে নিম্নোক্ত চারটি উপায়ে লেখা হয়।
new Date()
new Date(milliseconds)
new Date(dateString)
new Date(year, month, day, hours, minutes, seconds, milliseconds)
এখানে প্যারামিটার গুলো ঐচ্ছিক বিষয়। ডেট অবজেক্ট তৈরি করার পর আপনি এর সকল মেথড ব্যবহার করতে পারবেন। কিছু মেথডের লিষ্ট এবং কাজ বা বর্ননা নিম্নে দেয়া হল

মেথড
বর্ননা
getFullYear()
Returns year in full 4 digit format (ie: 2004).
getYear()
Returns the year, in 4 digit format or otherwise depending on browser. Deprecated in favor of getFullYear().
getMonth()
Returns the month. (Range is 0-11)!
getDate()
Returns the day of the month (Range is 1-31)
getDay()
Returns the day of the week (Range is 0-6). 0=Sunday, 1=Monday, etc.
getHours()
Returns the hour (Range is 0-23).
getMinutes()
Returns the minutes. (Range is 0-59).
getSeconds()
Returns the seconds. (Range is 0-59).
getMilliseconds()
Returns the milliseconds. (Range is 0-999).
getTime()
Returns the millisecond representation of the current Date object. In the words, the number of milliseconds between 1/1/1970 (GMT) and the current Date object.
getTimezoneOffset()
Returns the offset (time difference) between Greenwich Mean Time (GMT) and local time of Date object, in minutes.
getUTCFullYear()
Returns the full 4 digit year in Universal time.
getUTCMonth()
Returns the month in Universal time.
getUTCDate()
Returns the day of the month in Universal time.
getUTCDay()
Returns the day of the week in Universal time.
getUTCHours()
Returns the hour in Universal time.
getUTCMinutes()
Returns the minutes in Universal time.
getUTCSeconds()
Returns the seconds in Universal time.
getUTCMilliseconds()
Returns the milliseconds in Universal time.


setFullYear(year, [month], [day])
Sets the year of the Date object. (year: 4 digit year).
setYear(year)
Sets the year of the Date object. "year" can be two digits (1900 is automatically added to it), or 4 digits. Deprecated over setFullYear() above.
setMonth(month, [day])
Sets the month of the Date object. (month: 0-11)
setDate(day_of_month)
Sets the day of the month of the Date object. (day_of_month: 1-31).
setHours(hours, [minutes], [seconds], [millisec])
Sets the hour of the Date object. (hours: 0-23).
setMinutes(minutes, [seconds], [millisec])
Sets the minutes of the Date object. (minutes: 0-59).
setSeconds(seconds, [millisec])
Sets the seconds of the Date object. (seconds: 0-59).
setMilliseconds(milli)
Sets the milliseconds field of the Date object. (milli: 0-999)
setTime(milli)
Sets the value of the Date object in terms of milliseconds elapsed since 1/1/1970 GMT.
setUTCFullYear(year, [month], [day])
Sets the year of the Date object in Universal time.
setUTCMonth(month, [day])
Sets the month in Universal time.
setUTCDate(day_of_month)
Sets the day of the month in Universal time.
setUTCHours(hours, [minutes], [seconds], [millisec])
Sets the hours in Universal time.
setUTCMinutes(minutes, [seconds], [millisec])
Sets the minutes in Universal time.
setUTCSeconds(seconds, [millisec])
Sets the seconds in Universal time.
setUTCMilliseconds(milli)
Sets the milliseconds in Universal time.


toGMTString()
Converts a date to a string, using the GMT conventions. Deprecated in favor of toUTCString().
toLocaleString()
Converts a date to a string, using current locale conventions.
toLocaleDateString()
Returns the date portion of the Date as a string, using current locale conventions.
toLocaleTimeString()
Returns the time portion of the Date as a string, using current locale conventions.
toString()
Converts a Date to human-readable string.
toUTCString()
Converts a Date to human-readable string, in Universal time.
parse(datestring)
Returns the number of milliseconds in a date string since 1/1/1970. (datestring: a string containing the date/time to be parsed).
UTC(year, month, [day], [hours], [minutes], [seconds], [milli])
Returns the number of milliseconds in a date string since 1/1/1970, Universal time.
valueOf()
Converts a Date to milliseconds. Same as getTime();.

বিঃ দ্রঃ আমরা উদাহরনে যে সকল মেথড গুলো ব্যবহার করব, উপরের লিষ্ট থেকে সে সকল মেথড গুলো কোন ভ্যালু রিটান করে তা ভালভাবে বুঝে নিতে হবে। তাহলে আপনি অনায়াসে মেথডগুলো ব্যবহার করতে পারবেন।
get Full year( ), get Month( ), get Date( )  মেথডের ব্যবহার
এই তিনটি মেথড ব্যবহার করে আমরা আজকের তারিখ নির্নয় করব।
চলুন নিচের প্রোগ্রামটি প্র্যাকটিস  করা যাক
প্রোগ্রাম : get Full year( ), get Month( ) , get Date( )  মেথডের উদাহরন
১.        আপনার এডিটরে নিম্নোক্ত কোডগুলো লিখুন। এবার ফাইলটিকে কে একটি নির্দিষ্ট  নামে  সেভ করুন। আমরা এখানে program_0071.html নামে সেভ করেছি
<html>
<head>
    <title>Find Today</title>
</head>
<body>
<script type="text/javascript">
    var mydate = new Date()
    var Year = mydate.getFullYear()
    var Month = mydate.getMonth() + 1
    var Day = mydate.getDate()
    document.write("Today's date is: ")
    document.write(Day + "-" + Month + "-" + Year);   
</script>
</body>
</html>
ফলাফল :    এবার আপনার ব্রাউজারে program_0071.html ফাইলটি ওপেন করুন। আজকের দিনটি দেখা যাবে এখানে।
ব্যাখ্যা:  Mydate = new Date ( ) দ্বারা Date অবজেক্ট ডিকলার করা হল।
এবার যেহেতু get Full year ( ) , বছর রিটার্ন করে তাই একে আমরা Year ভেরিয়েবলে রেখে দিলাম।
এভাবে  Day = mydate, getDate () এবং Month = mydate- getMonth ( ) + 1
এবার document . write ( ) – ফাংশনে Day – Month – year এই ফরম্যাটে এ আউটপুট দেখানো হল।

get Date() এর ব্যবহার
get Day () ব্যবহার করে আমরা আজকের দিন নির্নয় করব। নিচের প্রোগ্রামটি প্রাকটিস করা যাক
প্রোগ্রাম : get Date()-এর  উদাহরন
১.        আপনার এডিটরে নিম্নোক্ত কোডগুলো লিখুন।এবার ফাইলটিকে কে একটি নির্দিষ্ট  নামে  সেভ করুন। আমরা এখানে program_0072.html নামে সেভ করেছি
<html>
<head>
    <title>getDay() </title>
</head>
<body>
<script type="text/javascript">

    var mydate = new Date()

    var Today = mydate.getDay();
    var weekday = new Array("Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    document.write("Today is " + weekday[Today]);   
   
</script>
</body> </html>
ফলাফল :    এবার আপনার ব্রাউজারে program_0072.html ফাইলটি ওপেন করুন। নিচের মত ফলাফল দেখতে পাবেন


ব্যাখ্যা: এখানে সপ্তাহ শুরু sunday ধরা হয়েছে। Today  ভেরিয়েবেলের মান আজকে দিনের মান সংখ্যাগত মান তাই একটি week day অ্যারেতে আমরা দিনের  নাম গুলো রেখে আজকের দিনটি নির্নয় করা হয়েছে।
সময় নির্নয় করা- চলুন নিচের প্রোগ্রামটি প্রাকটিস করা যাক।
প্রোগ্রাম : সময় নির্নয় করা
১।        আপনার এডিটরে নিম্নোক্ত কোডগুলো লিখুন।এবার ফাইলটিকে কে একটি নির্দিষ্ট  নামে  সেভ করুন। আমরা এখানে program_0073.html নামে সেভ করেছি
<!DOCTYPE html>
<html>
<head>
<title>Clock</title>
<script>
    function startTime() {
        var today = new Date();
        var hour = today.getHours();
        var min = today.getMinutes();
        var sec = today.getSeconds();
        min = checkTime(min);
        sec = checkTime(sec);
        document.getElementById('divClock').innerHTML = hour + ":" + min + ":" + sec;
        t = setTimeout(function() { startTime() }, 500);
    }
    function checkTime(i) {
        if (i < 10) {
            i = "0" + i;
        }
        return i;
    }
</script>
</head>
<body onload="startTime()">
<div id="divClock"></div>
</body> </html>
ফলাফলঃ ব্রাউজারে প্রোগ্রামটি ওপেন করুন আপনি একটি ঘড়ি দেখতে পাবেন।
ব্যাখ্যাঃ প্রথমে today নামে ডেট অবজেক্ট তৈরি করা হল এভাবে today = new Date () এর পর get Hour () , get Minutes () এবং get seconds () মেথড ব্যবহার করে আমরা hour, min, sec নির্নয় করে নিলাম। এবার chack time নামে একটি ফাংশন তৈরি করা হল যার কাজ যদি Min এবং Sec 10 এর কম হয় তবে সেই Min এর Sec এর আগে একটি ০ বসানো। যেমন 09 এভাবে। এবার div colck নামক Div এ সময় প্রদর্শন করা হল। আর set Timeout মেথড দ্বারা start Time () অর্থাৎ আমাদের মূল ফাংশনকে প্রতি 500 মিলিসেকেন্ডে কল করা হল। এভাবে একটি ঘড়ি তৈরি করা যায়।
Set Date () এর ব্যবহার
Set Date () মূলত আপনার ডেট অবজেক্ট এর সাথে কোন ভ্যালু সেট করে তা রিটার্ন করে যেমন আমরা তিন দিন আজকের দিনের সাথে যোগ বা বিয়োগ করব।    নিচের প্রোগ্রামটি লক্ষ করুন
প্রোগ্রাম : Set Date () এর উদাহরন
১.        আপনার এডিটরে নিম্নোক্ত কোডগুলো লিখুন। এবার ফাইলটিকে কে একটি নির্দিষ্ট  নামে  সেভ করুন। আমরা এখানে program_0074.html নামে সেভ করেছি
<!DOCTYPE html>
<html>
<head>
<title>SetDate</title>
<script>
    var today = new Date();
    var day = today.getDay();
    var AddDay = today.setDate(day + 3);
    var SubDate = today.setDate(day - 3);   
    document.write("After 3 Day :" + AddDay);
    document.write("<br>");
    document.write("Before 3 Day :" + SubDate);
</script>
</head>
<body onload="startTime()">
<div id="divClock"></div>
</body> </html>
ফলাফলঃ ব্রাউজারে প্রোগ্রামটি ওপেন করুন


এভাবে set Hour(), set Time() ইত্যাদি ব্যবহার করে প্রাকটিস করুন। সকল মেথড গুলো দিয়ে এবার নিজে নিজে প্রাকটিস করুন।
Previous Post                                                                                           Next Post

  বিস্তারিত জানতে নিচের বইটি সংগরহ করে নিন।

Book Name: Mastering Microsoft  Word
Writer: Bappi Ashraf
Published By: Gyankosh Prokashani
Amount of Pages: 464
First Publish: October-2004
Last Edition: We've February-2015 edition. Future edition may be existed!
Book Price: BDT 350 (30% Discount)
 The writer of this book has told that he has written this book with the concept of "teach yourself". On the other hand, Web Design is a thing which is interesting to learn. He has also told that the book is full of fan and enjoyment so that a person can learn Web Design by himself by playing with the example projects of this book.  Book's CD Link below... 

 cd

RELATED POST LINKS BELOW ********************************************