Saturday, February 7, 2015

How to Show Pop Up Boxes Using JavaScript?

How to Show Pop Up Boxes Using JavaScript?

Using JavaScript you can create three kinds of pop-up boxes, Alert box, Confirm box and prompt box.

Alert Box


An alert box is used if you want to make sure information comes through to the user. When an alert box pops up, the user will have to click on "OK" to processed.

Syntax:

alert("Alert Text")

Example:

<html>
<head>
<script type="text/javascript">
function display_alert()
{
alert("This is an alert box!")
}
</script>
</head>
<body>
<input type="button" onclick="display_alert()" value="Display alert box"/>
</body>
</html>

Preview:




 Conform box


A conform box is used if you want the user to verify or accept something. When a conform box pops up, the user will have to click either "OK" or "Cancel" to processed. If the user clicks "OK" the box returns true. If the user clicks "Cancel", the box returns false.

Syntax:

confirm{"Conform Text")

Example:

<html>
<head>
<script type="text/javascript">
function display_conform(){

r=confirm("Press a button");
if (r===true)
{
alert("You pressed OK!");
}
else
alert("You pressed Cancel");
}
</script>
<body>
<input type="button" onclick="display_conform()" value="Display a confirm box"/>
</body>
</html>

Preview:



 Prompt Box


A prompt box is used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click "OK" or "Cancel" to processed entering in input value.
If the use clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null.

Syntax:

prompt{"sometext", "defaultvalue"}

Example:

<html>
<head>
<script type="text/javascript">
function display_prompt(){
name=prompt("Please enter your name", "Your Name");
if ((name!=null) && name!=" ")
{
alert("Hello "+name+"! How are you today?");
}
}
</script>
</head>
<input type="button"onclick="display_prompt()" value="Display a prompt box"/>
</body>
</html>

Preview:


Related Search Terms

How to Write Conditional Statements in JavaScript?

How to Write Conditional Statements in JavaScript?

The different types of conditional statements used in JavaScript for making different decisions are as follows.

If Statement


This statement is used to execute some code only if a specified condition is true.

Syntax:

if {condition}
{
code to be executed if condition is true
}

Example:

<script type="text/javascript">
var d=new Date()
var time=d.getHours()
if (time<10)
{
document.write("<b>Good morning</b>")
}
</script>

This script writes "Good morning" greeting if the time is less than 10

If .... elese statement


This statement is used to execute some code only if the condition is true and another code if the condition is false.

Syntax:

if {condition}
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}

Example:

<script type="text/javascript">
var d=new Date()
var time=d.getHours()
if (time<10)
{
document.write("Good morning")
}
else
{
document.write("Good Day")
}
</script>

Preview:



If .... else If ..... else statement


This statement is used to select one of many blocks of code to be executed.

Syntax:

if {condition}
{
code to be executed if condition1 is true
}
else if {condition2}
{
code to be executed if condition2 is true
}
else
{
code to be executed if condition1 and condition2 are not true.
}

Example:

<script type="text/javascript">
var d=new Date()
var time=d.getHours()
if (time<10)
{
document.write("Good morning")
}
else if (time>=10 && time<16)
{
document.write("Good Day")
}
else
{
document.write("Hello World")
}
</script>

Preview:



Switch statement


This statement is used to select one of many blocks of code to be executed.

Syntax:

switch(n)
{
case 1:
execute code block 1
break;
case 2:
execute code block 2
break;
default:
code to be executed if n is different from case 1 and 2
}

Example:

<script type="text/javascript">
var d=new Date();
theDay=d.getDay();
switch(theDay)
{
case 5:
document.write("Good Friday");
break;
case 6:
document.write("Super Saturday");
break;
case 0:
document.write("Sleepy Sunday");
break;
default:
document.write("I am looking forward to this weekend!");
}</script>

Preview:


How to Write JavaScript With HTML?

How to Write JavaScript With HTML?

JavaScript is the most popular scripting language in the web to improve the design, validate forms, detect browsers, create cookies and many more client side functionalities and works in all major browsers, such as Internet Explorer, Mozilla Firefox, Google Chrome, Netscape, Opera and many more.

It is a lightweight programming language consisting of lines of executable computer code and usually embedded directly into HTML pages.

To write JavaScript with HTML page, you have to use the <script> tag along with the type attribute to define the scripting language. So the <script type="text/javascript"> and </script> tells where the javascript starts and end.


Different Ways to Write JavaScript with HTML


There are different ways to write JavaScript with HTML, which are as follows.

Scripts in the HEAD Section

When scripts are placed in head section, they needs to be executed when they are called, or when an event is triggered and it will ensure that the script is loaded before anyone uses it.

You can write <script> tag in the head section as follows.

<html>
<head>
<script type="text/javascript">
javascript codes are written here
</script>
</head>
<body>
</body>
</html>

Scripts in the BODY section

As in the head section, you can also place JavaScript codes in the body section using <script> tag and it will be executed when the page loads.

You can write <script> tag in the body section as follows.

<html>
<head>
</head>
<body>
<script type="text/javascript">
javascript codes are written here
</script>
</body>
</html>

Scripts in both the HEAD and BODY section

You can write <script> tag in both the head and body section as follows.

<html>
<head>
<script type="text/javascript"> 
javascript codes are written here
</script>
</head>
<body>
<script type="text/javascript">
javascript codes are written here
</script>
</body>
</html>


Scripts Using an External JavaScript File

If you needs to write same JavaScript code on several pages, you can write it on separate external page with a .js file extension and can link it to the HTML file.

You can link external JavaScript file to HTML file as follows.

<html>
<head>
<script src="javascript.js">
</script>
</head>
<body>
</body>
</html>

Read Next:

Related Search Terms

Sunday, February 1, 2015

How to create a simple form using HTML?

How to create a simple form using HTML?

From is a necessary element in any website or blog. Mostly they are used to take user information for any of the purposes like logging into the user account, creating user account, allowing to subscribe malling list, allowing users to submit comments and allowing users to contact website admin, support or sales team.

Here I am going to describe "How to create a simple form using HTML" step by step with describing what is a form and what elements are used to create HTML form along with complete HTML code for a form.

A form is an area that contain form elements. You must set up a form before adding in run to the web page. To setup a form, you need to specify two important information Method and Action.

Method is a property tells the form how to transfer the data to the form processor. The value for method can be 'post' or 'get' In post method you are just posting information and method get means that you are just going to get another page. In almost all of the form post method is used.

Action property tells what action the form should take when the user presses the submit button. Action is the URL to which you are posting the information.

We have to use different HTML tags to create a form. The most commonly used HTML tags to create a form are listed below.


Different Tags for HTML Form


<INPUT> Tag: The most form tag is <INPUT> tag. The type of INPUT is specified with the TYPE attribute. This tag doesn't have its ending tag. The most commonly used INPUT types are listed below:

TEXT: It is used for plain type of text input. The attributes used in this type are NAME, VALUE, SIZE and MAXLENGTH.

Example: <INPUT TYPE="TEXT" NAME="UserName" VALUE="Username" SIZE=16 MAXLENGTH=15>


PASSWORD: It is used for password type of text input. The attributes used in this type are NAME, VALUE, SIZE and MAXLENGTH.

Example: <INPUT TYPE="PASSWORD" NAME="Password" VALUE="Password" SIZE=16 MAXLENGTH=15>


RADIO: It is used for single choice input system. The attributes used in this type are NAME, VALUE and CHECKED

Example: <INPUT TYPE="radio" NAME="sex" VALUE="M" CHECKED>


CHECKBOX: It is used for multiple choice input system. The attributes used in this type are NAME and VALUE.

Example: <INPUT TYPE="checkbox" NAME="MCQ" VALUE="M">


RESET: It is used to reset values entered in a form. Value is the attribute of RESET type of INPUT. 
Example: <INPUT TYPE="reset" VALUE="Clear Form">


SUBMIT: It is used to submit values entered in a form. Value is the attribute of SUBMIT type of INPUT.

Example: <INPUT TYPE="submit" VALUE="Submit">

<TEXTAREA> Tag: This tag is used to specify the area of the text. This tag makes a two dimensional text area, in which viewer can type from a short sentence to many paragraphs. This tag has its ending tag and it is mostly used to create comment form or contact form. The attributes in this tag are NAME, VALUE, COLS and ROWS.

Example: <TEXTAREA NAME="Details" COLS=30 ROWS=5></TEXTAREA>

<SELECT> Tag: This tag is used to create a menu that offers visitors a list of option to choose from. This tab has also its ending tag. The attributes in this tag are NAME, MULTIPLE and SIZE.

Example: <SELECT NAME="Menu" MULTIPLE SIZE=3><OPTION>.....</SELECT>

<OPTION> Tag: It is the mini tag of <SELECT> tag. This tag is used to define the options to choose from the drop-down list. SELECTED is the attribute of <OPTION> Tag.

Example: <SELECT NAME="Menu" MULTIPLE SIZE=3><OPTION SELECTED>Programming Guide<OPTION>MCQs</SELECT>

Here is a sample form to allow users to create user and subscribe for the topics they want along with complete HTML code and its output.

HTML Code to Create a Simple Form


<html>
<head><title>Subscription Form</title></head>
<body>
<h1 align=center>Subscription Form</h1>
<br/>
<FORM METHOD='POST' ACTION=mailto:siteforinfotech@gmail.com>
<DIV>First Name:<INPUT TYPE='text' NAME='fname' VALUE='Enter First Name' SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Last Name:<INPUT TYPE='text' NAME='lname' VALUE='Enter Last Name' SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Password:<INPUT TYPE='password' NAME='password' SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Retype Password:<INPUT TYPE='password' NAME='rpassword' SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Email:<INPUT TYPE='text' NAME='email' VALUE='Enter Your Email' SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Sex:<INPUT TYPE='radio' NAME='sex' VALUE='M'>Male<INPUT TYPE='radio' NAME='sex' VALUE='F'>Female</DIV><br/>
<DIV>Write About You:<TEXTAREA NAME='about' COLS=30 ROWS=4></TEXTAREA></DIV><br/>
<DIV>Your Academic Level: <SELECT><OPTION>High School<OPTION>College Degree<OPTION>University Degree</SELECT></DIV><br/>
<DIV>Select your Topic to Subscribe:<br/><INPUT TYPE='checkbox' NAME='topic' VALUE='M'>Multiple Choice Questions<br/>
<INPUT TYPE='checkbox' NAME='topic' VALUE='T'>IT Tutorials<br/>
<INPUT TYPE='checkbox' NAME='topic' VALUE='P'>Programming Guide<br/><br/>
<INPUT TYPE='submit' VALUE='Submit'><INPUT TYPE='reset' VALUE='Reset'>
</FORM>
</body>
</html>

Preview of the above HTML Code

 

Subscription Form


First Name:

Last Name:

Password:

Retype Password:

Email:

Sex:MaleFemale

Write About You:

Your Academic Level:

Select your Topic to Subscribe:
Multiple Choice Questions
IT Tutorials
Programming Guide



Here I have posted the HTML codes for sample only. You can customize this form according to your requirement. You can extract and use any element to create your own form.



Related Posts:

    Saturday, January 31, 2015

    Solved MCQ on Core Operating System Principle set-13

    Solved MCQ on Core Operating System Principle set-13

    1) In memory management, a technique called as paging, the physical memory is broken into fixed sized blocks called .........

    A. pages

    B. frames

    C. blocks

    D. segments


    2) Which method is used to recover from deadlock?

    A. Process termination

    B. Resource preemption

    C. Resource non-preemption

    D. Process termination and Resource preemption


    3) Saving the state of the old process and loading the saved state of the new process is called ....

    A. context switch

    B. static

    C. multi programming

    D. none of the above


    4) The degree of Multiprogramming is controlled by ......

    A. CPU scheduler

    B. context switching

    C. long term scheduler

    D. medium term scheduler


    5) Input transfers are done in advance and output transfers are done after sometimes in which of these technique?

    A. Spooling

    B. Buffering

    C. Swapping

    D. Paging


    6) A binary semaphore .........

    A. has the values one or zero

    B. is essential to binary computers

    C. is used only for synchronization

    D. is used only for mutual exclusion


    7) A scheduling algorithm is fair .......

    A. if no process faces starvation.

    B. if a process is starved, detect it and run it with high priority

    C. if it uses semaphores

    D. only if a queue is used for scheduling


    8) Which of the following is also known as Double buffering?

    A. anticipated buffering

    B. buffer swapping

    C. circular buffering

    D. swapping buffering


    9) .......... is the ability of a system to continue functioning in the event of partial system failure.

    A. fault avoidance

    B. fault tolerance

    C. fault detection

    D. fault recovery


    10) Virtual memory is .........

    A. an extremely large main memory

    B. an extremely large secondary memory

    C. an illusion of extremely large main memory

    D. a type of memory used in super computers


    11) Error handling and I/O interrupt handling are the functions of ......

    A. I/O device Handler

    B. I/O traffic controller

    C. I/O scheduler

    D. I/O buffer


    12) In a multi-threaded environment..........

    A. each thread is allocated with new memory from main memory

    B. main thread terminates after the termination of child threads

    C. every process can have only one thread

    D. none of the above


    13) The kernel keeps track of the state of each task by using a data structure called ......

    A. process control block

    B. user control block

    C. memory control block

    D. hardware control block


    14) A virtual device is a ..........

    A. dedicated for none purpose

    B. shared device converted to a dedicated device

    C. dedicated device converted to a shared device

    D. shared device


    15) CPU scheduling is the basis of ...........operating system.

    A. batch

    B. real time

    C. multiprogramming

    D. monoprogramming


    16) ......... is a high speed cache used to hold recently referenced page table entries a part of paged virtual memory.

    A. Translation look a side buffer

    B. Inverse page table

    C. Segmented page table

    D. Indexed page table


    17) A technique that smooths out peaks in I/O demand is ........

    A. spooling

    B. buffering

    C. swapping

    D. paging


    18) In kernel model, the operating system services such as process management, memory management are provided by the kernel.

    A. monolithic

    B. micro

    C. macro

    D. Complex


    19) A process is said to be in ........... state if it was waiting for an event that will never occur.

    A. safe

    B. unsafe

    C. starvation

    D. dead lock


    20) Which of the following is an example of spooled device?

    A. The terminal used to enter the input data for a program being executed

    B. The secondary memory device in a virtual memory system

    C. A line printer used to print the output of a number of jobs

    D. None of the above

    Answers:

    1) B. frames
    2) D. Process termination and Resource preemption
    3) A. context switch
    4) C. long term scheduler
    5) B. Buffering
    6) A. has the values one or zero
    7) A. if no process faces starvation
    8) B. buffer swapping
    9) B. fault tolerance
    10) C. an illusion of extremely large main memory
    11) A. I/O device Handler
    12) B. main thread terminates after the termination of child threads
    13) A. process control block
    14) B. shared device converted to a dedicated device
    15) C. multiprogramming
    16) A. Translation look a side buffer
    17) B. buffering
    18) A. monolithic
    19) D. dead lock
    20) C. A line printer used to print the output of a number of jobs


    Related Posts:

    More MCQs on Operating System

    Objective Questions on Core Operating System set-12

    Objective Questions on Core Operating System set-12

    1) An optimal scheduling algorithm in terms of minimizing the average waiting time of a given set of process is ...

    A. FCFS scheduling

    B. Round robin scheduling algorithm

    C. Shortest job first scheduling algorithm

    D. Priority scheduling algorithm


    2) The hardware mechanism that enables a device to notify the CPU is called .......

    A. polling

    B. interrupt

    C. system call

    D. none of the above


    3) In the running state ........

    A. only the process which has control of the processor is found

    B. all the process waiting for I/O to be completed are found

    C. all the processes waiting for the processor are found

    D. none of the above


    4) Which technique was introduced because a single job could keep both the CPU and the I/O devices busy?

    A. Time sharing

    B. Spooling

    C. Preemptive scheduling

    D. Multiprogramming


    5) RMA works on static priorities while EDF algorithm works on ........

    A. starvation

    B. dynamic priorities

    C. RR scheduling

    D. FIFO scheduling


    6) In the ........... method of data transfer, the participation of the processor is eliminated during data transfer.

    A. buffering

    B. caching

    C. direct memory access

    D. indirect memory access


    7) Inter process communication can be done through ....

    A. mails

    B. messages

    C. system calls

    D. traps


    8) RR scheduling is most suitable for ........

    A. time shared OS

    B. distributed OS

    C. real time OS

    D. an Ordinary OS


    9) The aim of ......... transparency is to ensure that the movement of the object is handled automatically by the system in a user transparent manner.

    A. location

    B. name

    B. migration

    D. scaling


    10) ........... is a memory management scheme that permits the physical address space of a process to be noncontiguous.

    A. Paging

    B. Segmentation

    C. Virtual memory

    D. main memory


    11) Context switching is ........

    A. part of spooling

    B. part of polling

    C. part of interrupt handling

    D. part of paging


    12) The normal functioning of an RPC may get disrupted due to ..........

    A. call message gets lost

    B. response message gets lost

    C. callee node and caller node crashes and is restarted

    D. All of the above


    13) Mutual exclusion is referred as .......

    A. if one process is in a critical region others are excluded

    B. prevents deadlock

    C. requires semaphore to implement

    D. is found only in the windows NT operating system


    14) IFO scheduling is ..........

    A. preemptive

    B. non-preemptive

    C. deadline scheduling

    D. RR scheduling


    15) .......... deals with the process of deciding which process should be assigned to which processor.

    A. Process migration

    B. Processor allocation

    C. threads

    D. none of the above


    16) Which scheduler controls the degree of multiprogramming?

    A. Short term scheduler

    B. Long term scheduler


    C. Middle term scheduler

    D. Pre term scheduler


    17) Safe state is .......

    A. deadlock state

    B. non-deadlocked state

    C. polling state

    D. spooling state


    18) ........ time is defined as the time period for which the execution of the process is stopped for transferring its information to the destination node.

    A. turn around

    B. latency

    C. freezing

    D. execution



    19) The principle of locality of reference justifies the use of

    A. virtual memory

    B. interrupts

    C. main memory

    D. cache memory


    20) For a multiple instances of resource type which algorithm is used .......

    A. divide and conquer algorithm

    B. banker's algorithm

    C. partition algorithm

    D. sorting algorithm


    Answers:

    1) C. Shortest job first scheduling algorithm
    2) B. interrupt
    3) A. only the process which has control of the processor is found
    4) D. Multiprogramming
    5) C. RR scheduling
    6) C. direct memory access
    7) B. messages
    8) A. time shared OS
    9) B. migration
    10) A. Paging
    11) C. part of interrupt handling
    12) D. All of the above
    13) A. if one process is in a critical region others are excluded
    14) B. non-preemptive
    15) B. Processor allocation
    16) B. Long term scheduler
    17) B. non-deadlocked state
    18) C. freezing
    19) D. cache memory
    20) B. banker's algorithm


    Related Posts:

    More MCQs on Operating System

    Wednesday, January 28, 2015

    Interview Questions on Operating System Basis set-11

    Interview Questions on Operating System Basis set-11

    1) Which of the following is crucial time while accessing data on the disk?

    A. Seek time

    B. Rotational time

    C. Transmission time

    D. Waiting time


    2) What is the primary job of the operating system is a computer?

    A. Command resources

    B. Manage resources

    C. Provide utilities

    D. Be user friendly


    3) The ......... is a user process that initiates a remote procedure call.

    A. client

    B. server

    C. network

    D. operating system


    4) Which of the following memory allocation scheme suffers from external fragmentation?

    A. Segmentation

    B. Pure demand paging

    C. Swapping

    D. Paging


    5) Which of the following is used to removal of process from active contention of CPU and reintroduce them into memory later?

    A. Interrupt

    B. Swapping

    C. Signal

    D. Thread


    6) The operating system manages .....

    A. memory

    B. processor

    C. disk and I/O devices

    D. all of the above


    7) Information about a process is maintained in a .........

    A. stack

    B. translation look a side buffer

    C. process control block

    D. program control block


    8) Paging .........

    A. solves the memory fragmentation problem

    B. allows modular programming

    C. allows structured programming

    D. avoids deadlock


    9) Which is not the layer of the Operating system?

    A. Kernel

    B. Shell

    C. Application program

    D. Critical Section


    10) Distributed OS works on the ............ principle.

    A. file foundation

    B. single system image

    C. multi system image

    D. networking image


    11) The collection of processes on the disk that is waiting to be brought into memory for execution forms the .......

    A. ready queue

    B. device queue

    C. input queue

    D. priority queue


    12) In ....... condition, processes are allowed to request for new resources without releasing the resources that they are currently holding.

    A. Mutual exclusion

    B. Hold and wait

    C. No preemption

    D. Circular wait


    13) The time taken by the disk arm to locate the specific address of a sector for getting information is called .....

    A. rotational delay

    B. seek time

    C. search time

    D. response time


    14) The principle of locality of reference justifies the use of ........

    A. virtual memory

    B. interrupts

    C. main memory

    D. cache memory


    15) In .......... condition, a resource that has been allocated to a process becomes available for allocation to another process only after it has been voluntarily released by the process holding it.

    A. Mutual exclusion

    B. Hold and wait

    C. No preemption

    D. Circular wait


    16) Identify the odd thing in the services of operating system ...

    A. Accounting

    B. Protection

    C. Error detection and correction

    D. Dead lock handling


    17) Multiprocessing ...........

    A. makes the operating system simpler

    B. allows multiple processes to run simultaneously

    C. is completely understood by all major computer vendors

    D. allows the same computer to have the multiple processors


    18) In ............. condition, two or more processes must form a circular chain in which each process is waiting for a resource that is held by the next member of the chain.

    A. Mutual exclusion

    B. Hold and wait

    C. No preemption

    D. Circular wait


    19) Which of the following is not advantage of multiprogramming?

    A. Increased throughput

    B. Shorter response time

    C. Decreased operating system overhead

    D. Ability to assign priorities of jobs


    20) Which is not a state of the process?

    A. Blocked

    B. Running

    C. Ready

    D. Privileged


    Answers:

    1) A. Seek time
    2) B. Manage resources
    3) A. client
    4) A. Segmentation
    5) B. Swapping
    6) D. all of the above
    7) C. process control block
    8) A. solves the memory fragmentation problem
    9) D. Critical Section
    10) B. single system image
    11) C. input queue
    12) B. Hold and wait
    13) B. seek time
    14) D. cache memory
    15) C. No preemption
    16) C. Error detection and correction
    17) D. allows the same computer to have the multiple processors
    18) D. Circular wait
    19) C. Decreased operating system overhead
    20) D. Privileged


    Related Posts:

    More MCQs on Operating System