Today, 24.12.11, is the first day of the Javascript tutorial here on quadd help. We have divided it in three tutorials, one tutorial per day. As follows:
Day 1
Javascript Popup Boxes:
Pop Up Boxes we have seen so many times on webpages daily. Sometimes they ask for some input from us, sometimes they provide quick output and sometimes they provide limited options in the form of OK and CANCEL buttons. Using Javascript we can create three types of dialog boxes:
In this course we will discuss only first two dialog boxes.
Alert Dialog Box
Syntax: alert("message or text");
Example Code:
Example Output:
Prompt Dialog Box
Syntax: prompt("Message or text","default value");
Example Code:
Example Output:
Sample program using Javascript Popup Boxes:
Code:
Output:
Readers can create their own examples. Please feel free to ask any doubts regarding this tutorial or about your own examples, today. Please allow 2-3 hours to answer your queries.
Tomorrow's topic: Javascript functions.
Quadd Notes for GMACPS Class X.
Lesson | Date | Topic |
One | 24.12.11 | Javascript Popup Boxes |
Two | 25.12.11 | Javascript Functions |
Three | 26.12.11 | Controlling Forms using Javascript & Calculator Example |
Day 1
Javascript Popup Boxes:
Pop Up Boxes we have seen so many times on webpages daily. Sometimes they ask for some input from us, sometimes they provide quick output and sometimes they provide limited options in the form of OK and CANCEL buttons. Using Javascript we can create three types of dialog boxes:
- Alert Dialog Box: It displays a message to the user with OK button to close it.
- Prompt Dialog Box: It displays user a message and also a text box to input some value with OK and CANCEL Buttons.
- Confirm Dialog Box: It displays user a message, just like Alert dialog box, but with extra CANCEL button along with OK button. Both buttons can be assigned different task by programming.
In this course we will discuss only first two dialog boxes.
Alert Dialog Box
Syntax: alert("message or text");
Example Code:
Example Output:
Prompt Dialog Box
Syntax: prompt("Message or text","default value");
Example Code:
Simple code using Prompt dialog box and alert dialog box together. |
Output1: First appearance of prompt dialog box with 'default value'. |
Output2: Demonstrates that use can input text into text box within prompt dialog box |
Output3: Alert dialog box displaying output. NOTE: to display output in webpage body use document.write() instead of alert(). |
Code:
Output:
Output1: User entered first number. (this number will be assigned to 'num1' variable). |
Output2: User entered second number. (this number will be assigned to 'num2' variable). |
Readers can create their own examples. Please feel free to ask any doubts regarding this tutorial or about your own examples, today. Please allow 2-3 hours to answer your queries.
Tomorrow's topic: Javascript functions.
Quadd Notes for GMACPS Class X.
In Prompt Dialog Box if we click on "cancel" button then also it show alert box with name="null"
ReplyDeletehow to solve this ?
You need to use IF statement to catch null. And if you don't have knowledge of IF statement then you can't do anything.
ReplyDeletewhat is parseInt and prompt??
ReplyDeletethat much i know that prompt is related to input parseint about no.s but sir could you please explain it...?
I think you have not read the tutorial fully.
ReplyDeleteprompt creates prompt dialog box for input (for more on prompt dialog box please refer to the tutorial above)
And Prompt dialog box comes with Text box for input. So what ever user enters either number or text, it will be accepted as text and text can not be used for mathematical operations. So, if user enters number in prompt dialog box and to ensure that it will be accepted as number by program ParseInt is used. It converts text to number (if text consists of any number).