السبت، 7 فبراير 2015

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 Show Pop Up Boxes Using JavaScript?

Posted at  11:45 م - by mego almasry 0

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

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 Conditional Statements in JavaScript?

Posted at  8:53 م - by mego almasry 0

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:


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

How to Write JavaScript With HTML?

Posted at  8:32 م - by mego almasry 0

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

الاثنين، 2 فبراير 2015

You can create changeable Date and Time using JavaScript Date object. JavaScript Date object will automatically hold the current date and time as its initial value. You can manipulate it easily by using different methods in Date object. The different methods in Date object I am going to use to create changeable Date and Time are as follows.

  • Date():    Returns today's date and time.
  • getDate(): Returns the day of the month from a Date object from 1-31.
  • getDay():  Returns the day of the week from a Date object from 1-6
  • getMonth():Returns the month from a Date object from 0-11
  • getFullYear(): Returns the year, as a four digit number from Date object.
  • getHours():   Returns the hour of a Date object from 0-23.
  • getMinutes(): Returns the minutes of a Date object from 0-59
  • getSeconds(): Returns the seconds of a Date object from 0-59

Do do rest of the work you have to create a new Date() object and needs to use that value to get date, month, day name and time with hours, minutes and seconds. You can create variables for day, month and year as follows.

var now=new Date();
var today=now.getDate();
var month=now.getMonth();
var year=now.getFullYear();
var day=now.getDay();

You can create variables for hours, minutes and seconds as follows.

var now=new Date();
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();

After getting month and day in number format, you can change it into name of the month and day by using the arrays as follows.

var monthname=new Array(12)
monthname[0]="January ";
monthname[1]="February ";
monthname[2]="March ";
monthname[3]="April ";
monthname[4]="May ";
monthname[5]="June ";
monthname[6]="July ";
monthname[7]="August ";
monthname[8]="Septmber ";
monthname[9]="October ";
monthname[10]="November ";
monthname[11]="December ";

var dayname=new Array(7)
dayname[0]="Sunday ";
dayname[1]="Monday ";
dayname[2]="Tuesday ";
dayname[3]="Wednesday ";
dayname[4]="Thrusday ";
dayname[5]="Friday ";
dayname[6]="Saturday ";


Full HTML Code to Create Changeable Date


Here is a full HTML code to create changeable date, you can use these codes to display full date or you can customize to display in different format on your web page.

<html>
<body>
<script type="text/javascript">
function displayDate(){
var now=new Date();
var today=now.getDate();
var month=now.getMonth();

var monthname=new Array(12)
monthname[0]="January ";
monthname[1]="February ";
monthname[2]="March ";
monthname[3]="April ";
monthname[4]="May ";
monthname[5]="June ";
monthname[6]="July ";
monthname[7]="August ";
monthname[8]="Septmber ";
monthname[9]="October ";
monthname[10]="November ";
monthname[11]="December ";

var year=now.getFullYear();
var day=now.getDay();

var dayname=new Array(7)
dayname[0]="Sunday ";
dayname[1]="Monday ";
dayname[2]="Tuesday ";
dayname[3]="Wednesday ";
dayname[4]="Thrusday ";
dayname[5]="Friday ";
dayname[6]="Saturday ";

document.write(monthname[month]+today+ ", "+year+ " "+dayname[day]);
}
window.onload=displayDate();
</script>
</body>
</html>

Preview of Date Displayed:


Full HTML Code to Create Changable Time


Here is a full HTML code to create changeable time, you can use these codes to display full time or you can customize to display in different format on your web page. You can use these codes to create digital clock using JavaScript, which I have already posted in my previous post.

<html>
<head></head>
<body>
<script type="text/javascript">
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
var ap="AM";

//to add AM or PM after time

if(h>11) ap="PM";
if(h>12) h=h-12;
if(h==0) h=12;

//to add a zero in front of numbers<10

m=checkTime(m)
s=checkTime(s)

document.getElementById('clock').innerHTML=h+":"+m+":"+s+" "+ap
t=setTimeout('startTime()', 500)
}

function checkTime(i)
{
if (i<10)
{ i="0" + i}
return i
}

window.onload=startTime;

</script>

<div id="clock"></div>
</body>
</html>

Preview of Time Displayed:




Related Posts:

How to create Changeable Date and Time Using JavaScript?

Posted at  11:09 م - by mego almasry 0

You can create changeable Date and Time using JavaScript Date object. JavaScript Date object will automatically hold the current date and time as its initial value. You can manipulate it easily by using different methods in Date object. The different methods in Date object I am going to use to create changeable Date and Time are as follows.

  • Date():    Returns today's date and time.
  • getDate(): Returns the day of the month from a Date object from 1-31.
  • getDay():  Returns the day of the week from a Date object from 1-6
  • getMonth():Returns the month from a Date object from 0-11
  • getFullYear(): Returns the year, as a four digit number from Date object.
  • getHours():   Returns the hour of a Date object from 0-23.
  • getMinutes(): Returns the minutes of a Date object from 0-59
  • getSeconds(): Returns the seconds of a Date object from 0-59

Do do rest of the work you have to create a new Date() object and needs to use that value to get date, month, day name and time with hours, minutes and seconds. You can create variables for day, month and year as follows.

var now=new Date();
var today=now.getDate();
var month=now.getMonth();
var year=now.getFullYear();
var day=now.getDay();

You can create variables for hours, minutes and seconds as follows.

var now=new Date();
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();

After getting month and day in number format, you can change it into name of the month and day by using the arrays as follows.

var monthname=new Array(12)
monthname[0]="January ";
monthname[1]="February ";
monthname[2]="March ";
monthname[3]="April ";
monthname[4]="May ";
monthname[5]="June ";
monthname[6]="July ";
monthname[7]="August ";
monthname[8]="Septmber ";
monthname[9]="October ";
monthname[10]="November ";
monthname[11]="December ";

var dayname=new Array(7)
dayname[0]="Sunday ";
dayname[1]="Monday ";
dayname[2]="Tuesday ";
dayname[3]="Wednesday ";
dayname[4]="Thrusday ";
dayname[5]="Friday ";
dayname[6]="Saturday ";


Full HTML Code to Create Changeable Date


Here is a full HTML code to create changeable date, you can use these codes to display full date or you can customize to display in different format on your web page.

<html>
<body>
<script type="text/javascript">
function displayDate(){
var now=new Date();
var today=now.getDate();
var month=now.getMonth();

var monthname=new Array(12)
monthname[0]="January ";
monthname[1]="February ";
monthname[2]="March ";
monthname[3]="April ";
monthname[4]="May ";
monthname[5]="June ";
monthname[6]="July ";
monthname[7]="August ";
monthname[8]="Septmber ";
monthname[9]="October ";
monthname[10]="November ";
monthname[11]="December ";

var year=now.getFullYear();
var day=now.getDay();

var dayname=new Array(7)
dayname[0]="Sunday ";
dayname[1]="Monday ";
dayname[2]="Tuesday ";
dayname[3]="Wednesday ";
dayname[4]="Thrusday ";
dayname[5]="Friday ";
dayname[6]="Saturday ";

document.write(monthname[month]+today+ ", "+year+ " "+dayname[day]);
}
window.onload=displayDate();
</script>
</body>
</html>

Preview of Date Displayed:


Full HTML Code to Create Changable Time


Here is a full HTML code to create changeable time, you can use these codes to display full time or you can customize to display in different format on your web page. You can use these codes to create digital clock using JavaScript, which I have already posted in my previous post.

<html>
<head></head>
<body>
<script type="text/javascript">
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
var ap="AM";

//to add AM or PM after time

if(h>11) ap="PM";
if(h>12) h=h-12;
if(h==0) h=12;

//to add a zero in front of numbers<10

m=checkTime(m)
s=checkTime(s)

document.getElementById('clock').innerHTML=h+":"+m+":"+s+" "+ap
t=setTimeout('startTime()', 500)
}

function checkTime(i)
{
if (i<10)
{ i="0" + i}
return i
}

window.onload=startTime;

</script>

<div id="clock"></div>
</body>
</html>

Preview of Time Displayed:




Related Posts:

الأحد، 1 فبراير 2015

In the previous post, I have described about "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. In this post I am going to describe about to Validate a this HTML Form Using JavaScript.

You can validate a HTML Form Using JavaScript for the following circumstances.

  • Whether or not the user left required fields empty
  • Whether or not the user entered a valid e-mail address
  • Whether or not the user entered a valid date
  • Whether or not the user entered text in numeric field or entered number in text field

Here in this post I am going to describe you, "How to Validate Required Fields using JavaScript.

Validating Required Field using JavaScript


This JavaScript Function below checks if a required field has been left empty. If the required field is blank, an alert box alerts a message and the function returns false. If the value is entered the function returns true.

function validate_required(field, alerttxt)
{
with(field)
{
if (value===null||value==="")
{alert(alerttxt); return false;}
else {return true;}
}
}

Complete JavaScript Code with HTML for Validating Required Field


Here are the complete JavaScript codes along with complete HTML codes uses with the JavaScript Functions given below.

<html>
<head><title>Subscription Form</title>
<script type="text/javascript">
function validate_required(field, alerttxt)
{
with(field)
{
if (value===null||value==="")
{alert(alerttxt); return false;}
else {return true;}
}
}

function validate_form(thisform)
{
with(thisform)
{
if (validate_required(fname, "First name must be filled out!")===false)
{fname.foucus(); return false;}
if (validate_required(lname, "Last name must be filled out!")===false)
{lname.foucus(); return false;}
if (validate_required(password, "Password must be filled out!")===false)
{password.foucus(); return false;}
if (validate_required(rpassword, "Retype Password must be filled out!")===false)
{rpassword.foucus(); return false;}
}
}
</script>
</head>
<body>
<FORM METHOD='GET' ONSUBMIT="return validate_form(this);" ACTION="http://www.siteforinfotech.com/p/about-us.html">
<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/>
<br/>
<INPUT TYPE='submit' VALUE='Submit'><INPUT TYPE='reset' VALUE='Reset'>
</FORM>
</body>
</html>


Preview of the above HTML Code



First Name:

Last Name:

Password:

Retype Password:

Email:



How to Validate a HTML Form Using JavaScript?

Posted at  11:05 م - by mego almasry 0

In the previous post, I have described about "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. In this post I am going to describe about to Validate a this HTML Form Using JavaScript.

You can validate a HTML Form Using JavaScript for the following circumstances.

  • Whether or not the user left required fields empty
  • Whether or not the user entered a valid e-mail address
  • Whether or not the user entered a valid date
  • Whether or not the user entered text in numeric field or entered number in text field

Here in this post I am going to describe you, "How to Validate Required Fields using JavaScript.

Validating Required Field using JavaScript


This JavaScript Function below checks if a required field has been left empty. If the required field is blank, an alert box alerts a message and the function returns false. If the value is entered the function returns true.

function validate_required(field, alerttxt)
{
with(field)
{
if (value===null||value==="")
{alert(alerttxt); return false;}
else {return true;}
}
}

Complete JavaScript Code with HTML for Validating Required Field


Here are the complete JavaScript codes along with complete HTML codes uses with the JavaScript Functions given below.

<html>
<head><title>Subscription Form</title>
<script type="text/javascript">
function validate_required(field, alerttxt)
{
with(field)
{
if (value===null||value==="")
{alert(alerttxt); return false;}
else {return true;}
}
}

function validate_form(thisform)
{
with(thisform)
{
if (validate_required(fname, "First name must be filled out!")===false)
{fname.foucus(); return false;}
if (validate_required(lname, "Last name must be filled out!")===false)
{lname.foucus(); return false;}
if (validate_required(password, "Password must be filled out!")===false)
{password.foucus(); return false;}
if (validate_required(rpassword, "Retype Password must be filled out!")===false)
{rpassword.foucus(); return false;}
}
}
</script>
</head>
<body>
<FORM METHOD='GET' ONSUBMIT="return validate_form(this);" ACTION="http://www.siteforinfotech.com/p/about-us.html">
<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/>
<br/>
<INPUT TYPE='submit' VALUE='Submit'><INPUT TYPE='reset' VALUE='Reset'>
</FORM>
</body>
</html>


Preview of the above HTML Code



First Name:

Last Name:

Password:

Retype Password:

Email:



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:

    How to create a simple form using HTML?

    Posted at  12:26 ص - by mego almasry 0

    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:

      السبت، 31 يناير 2015

      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

      Solved MCQ on Core Operating System Principle set-13

      Posted at  10:06 م - by mego almasry 0

      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

      Copyright © 2013 hello1. by Bloggertheme9 Powered by Blogger.
      WP Theme-junkie converted by Blogger template