‏إظهار الرسائل ذات التسميات Internet & Web Designing. إظهار كافة الرسائل
‏إظهار الرسائل ذات التسميات Internet & Web Designing. إظهار كافة الرسائل
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:

    How to Load External JavaScript Asynchronously or Dynamically

    How to Load External JavaScript Asynchronously or Dynamically


    JavaScript makes more easier to manipulate websites, now a days most of the browsers supporting JavaScript codes. When the HTML parser encounters a <script> element, by default, run the script before it can parsing and rendering the document. It is not much problem for inline scripts but if the script source code is in an external file specified with a src attribute, the portions of the document that follow the Script will not appear in the browser until the script has been downloaded and executed.This makes loading of the website much slower, which makes bad user experience for your website and may not also indexing of your website by the search engines.


    This Synchronous or blocking script execution is the default only. The <script> tag can have defer and async attributes, which cause scripts to be executed differently. This makes your website loading much faster than before and appears contents of your site by loading at first.


    Loading JavaScript Asynchronously using async or defer attributes



    Both the defer and acync attributes are ways of telling the browser that the linked script does not use document.write() and won't be generating document content, and that therefore the browser can continue to parse and render the document while downloading the script. You can use async or defer attributes as the following.
    <script defer src="deferred.js"></script> 
    <script async src="async.js"></script>

    The defer attribute causes the browser to defer execution of the script until after the document has been loaded and parsed and is ready to be manipulated. The async attribute causes the browser to run the script as soon as possible but not to block document parsing while the script is being downloaded. If a <script> tag has both attributes, a browser that supports both will honor the async attribute and ignore the defer attribute. Deferred scripts run in the order in which they appear in the document, while acync scripts run as they load, which means that they may execute out of order.

    Here is an example of acync script uses in this blog for Intensedebate comments script source.

    <script async='async' expr:src='data:post.commentSrc' type='text/javascript'/>



    Loading JavaScript Asynchronously by loading scripts dynamically



    You can load and execute scripts asynchronously, even in browsers that do not support the async attribute, by dynamically creating a <script> element and inserting it into the document. Here is an example how to load scripts dynamically.

    function loadasync(url){
    var head=document.getElementByTagName("head")[0];
    var s=document.createElement("script");
    s.src=url;
    head.appendchild(s);
    }

    This loadsaync() function finds the <head> tag and attach <script> tag below opening of head tag and loads scripts dynamically. Scripts that are neither included inline within the web page or referenced statically from the web page are loaded into the document and become part of the running JavaScript program.

    You can use the following method to execute loadsync() function, when document finished loading.

    function loadasync(){ ..................}
    request.onreadystatechange=loadasync;

    Here is an example of loading JavaScript asynchronously by loading scripts dynamically used in this blog for external scripts from infolinks ads.

    <div style='display:none'>  <div id='adsource-0'>
    <script type='text/javascript'>
    var infolinks_pid = 9993182;
    var infolinks_wsid = 1;
    </script>
    <script language='javascript' src='http://resources.infolinks.com/js/infolinks_main.js' type='text/javascript'/>
    </div>
    </div>
    <script type='text/javascript'>
    source = document.getElementById("adsource-0");
    placeholder = document.getElementById("ad-0");
    placeholder.appendChild(source);
    </script>

    I have placed this code at the bottom of HTML codes, i.e. just before </body> tag and have placed the following code where I want to display ads.

    <div id="ad-0" align="center"></div>


    Loading JavaScript Asynchronously when document finishes loading 




    You can load and execute scripts asynchronously by using setTimeout(), addEventListner(), and attachEvent(). Most objects that can be event targets have a method named addEventListner(), which allows the registration of multiple listeners.

    window.addEventListner("load", function(){.....},false);
    request.addEventListner("readystatechange", function(){......},false);

    The first argument to this function is the name of the event. For IE8 and earlier, you must use a similar method, named attachEvent().

    window.attachevent("onload", function() {.....});

    Here is an example which define an onLoad() function that registers a function to be run when the document finishes loading. If the document has already loaded, run it asynchronously.

    function onLoad(f){
    if(onLoad.loaded)
    window.setTimeout(f,0);
    elseif (window.addEventListner)
    window.addEventListner("load",f,false);
    elseif (window.attachEvent)
    window.attachEvent("onload",f);
    }

    onLoad.loaded=false;

    onLoad(function(){onLoad.loaded=true;});


    In the above script window.attachEvent is used for IE8 and earlier. onLoad.loaded=false; sets a flag that indicates the document is not loaded yet and onLoad(function(){onLoad.loaded=true;}); register a function to set the flag when the document does load.



    Related Posts:



    How to Add Multiple Slideshows on One Page Using Javascript


    Most of our visitors asked "How to Add Multiple Slideshows on One Page Using JavaScript" by commenting on different previous posts for JavaScript slideshow and going to write this post about to add multiple slideshows on the same page. Using this script you can add number of slideshows on single page as your requirements. 


    Multiple Slideshows on One Page Using JavaScript



    To make multiple slideshows, at first you have to make variable lists for each slideshows and have to create new slideshow using function slideshow( ). Here I have created two slideshows with variables SlideList1 and SlideList2 and uses function slideshow with parameters slideList, image, speed and name.

    You can create number of new slideshows using this function below using new keyword. i.e. var slideshow1=new slideshow(slideList1, 'slide1', 3000, 'slideshow1');

    function SlideShow(slideList, image, speed, name)          
    {
    this.slideList = slideList;
    this.image = image;
    this.speed = speed;
    this.name = name;
    this.current = 0;
    this.timer = 0;
    }

    And the another function switchImage( ) given below allows you to  change images while playing slideshows.

    function switchImage(imgName, imgSrc) 
    {
    if (document.images)
    {
    if (imgSrc != "none")
    {
    document.images[imgName].src = imgSrc;
    }
    }
    }

    Here is a full JavaScript code for making multiple slideshows on one page using JavaScript. Copy the following codes inside body tag of your HTML file and replace given image source <img src=" "> with your image source.


    <img src="image1.gif" name="slide1">
    <img src="image2.gif" name="slide2">
    <script type=text/javascript>
    var SlideList1 = ['image1.gif', 'image2.gif', 'image3.gif'];
    var SlideShow1 = new SlideShow(SlideList1, 'slide1', 3000, "SlideShow1");
    var SlideList2 = ['image4.gif', 'image5.gif', 'image6.gif'];
    var SlideShow2 = new SlideShow(SlideList2, 'slide2', 1000, "SlideShow2");
    function SlideShow(slideList, image, speed, name)
    {
    this.slideList = slideList;
    this.image = image;
    this.speed = speed;
    this.name = name;
    this.current = 0;
    this.timer = 0;
    }
    function switchImage(imgName, imgSrc)
    {
    if (document.images)
    {
    if (imgSrc != "none")
    {
    document.images[imgName].src = imgSrc;
    }
    }
    }
    SlideShow.prototype.play = SlideShow_play;
    function SlideShow_play()
    {
    with(this)
    {
    if(current++ == slideList.length-1) current = 0;
    switchImage(image, slideList[current]);
    clearTimeout(timer);
    timer = setTimeout(name+'.play()', speed);
    }
    }
    window.onLoad=SlideShow1.play();SlideShow2.play();
    </script>


    Here the speed of first and second slideshows are specified 3000 and 1000 respectively, your can change them as your requirements. Also you can add more slideshows by adding more slideList and slideshow variables.


    Preview of  JavaScript Code Given Above



    slide1

    slide2



    You can add custom CSS codes to give different styles like setting border using border: property, give rounded corners using border-radius property as presented in the previous post "How to make rounded corners border using CSS" and can give different animation effects like fade effects, zoom effects, slide effects etc. 

    You can refer to the following previous posts to give fade effect animations using CSS, JavaScript or JQuery codes.



    Related Posts:






    How to create fade effect image slideshow using CSS


    You can give fade effect animation for image slideshow using CSS. @keyframes 'at' rule and animation keyword in CSS can be used to make image slideshow with fade effect. With @keyframes 'at' rule, you can define the properties that will be animated in an animation rule and animation keyword to set all of the animation properties.


    Here I have used different types of animation properties like animation-name, animation-duration, animation-timing-function and animation-iteration-count. Where animation-name specifies name of the animation, animation-duration specifies animation duration in second(s) or milisecond(ms), animation-timing-function specifies how the animation will play like ease, ease-in, ease-in-out, ease-out and linear and animation-iteration-count:number of times animation should play.

    Simple fade effect image slideshow 

     
    Here is a sample CSS code for creating simple fade effect image slideshow written for safari browser.

    <style type="text/css">
    @-webkit-keyframes fade{
    from {opacity:.5;}
    50% {opacity:1;}
    to {opacity:.5;}
    }
    #anim1 {-webkit-animation-name:fade;-webkit-animation-duration:5s;
    -webkit-animation-iteration-timing-function:linear;
    position:relative;-webkit-animation-iteration-count:infinite;}
    </style>

    Here is a full HTML code along with required JavaScript code for creating simple fade effect image slideshow.

    <head>
    <title>CSS Animations</title>
    <style type="text/css">
    @-webkit-keyframes fade{
    from {opacity:.5;}
    50% {opacity:1;}
    to {opacity:.5;}
    }
    @-moz-keyframes fade{
    from {opacity:.5;}
    50% {opacity:1;}
    to {opacity:.5;}
    }
    @-o-keyframes fade{
    from {opacity:.5;}
    50% {opacity:1;}
    to {opacity:.5;}
    }
    @-ms-keyframes fade{
    from {opacity:.5;}
    50% {opacity:1;}
    to {opacity:.5;}
    }
    #anim1 {-webkit-animation-name:fade;-webkit-animation-duration:5s;
    -webkit-animation-iteration-timing-function:linear;position:relative;
    -webkit-animation-iteration-count:infinite;-moz-animation-name:fade;
    -moz-animation-duration:5s;-moz-animation-iteration-timing-function:linear;
    -moz-animation-iteration-count:infinite;-o-animation-name:fade;
    -o-animation-duration:5s;-o-animation-iteration-timing-function:linear;
    -o-animation-iteration-count:infinite;-ms-animation-name:fade;
    -ms-animation-duration:5s;-ms-animation-iteration-timing-function:linear;
    -ms-animation-iteration-count:infinite;}
    </style>
    <script language="JavaScript">
    var i = 0;
    var path = new Array();

    // LIST OF IMAGES
    path[0] = "image1.jpg";
    path[1] = "image2.jpg";
    path[2] = "image3.jpg";

    function swapImage1()
    {
    document.slide.src = path[i];
    if(i < path.length - 1) i++; else i = 0;
    setTimeout("swapImage1()",5000);
    }
    window.onload=swapImage1;
    </script>
    </head>
    <body>
    <div id="anim1"><img height="400" name="slide" src="image_1.gif" width="600" />
    </div>
    </body>
    </html>


    In the above code prefixes -webkit-, -moz-, -o-, -ms- are used for browsers safari, firefox, opera and internet explorer respectively.

    Here is a preview of image slideshow for the code above.


    slide


    Fade effect image slideshow with caption


    You can add caption for this slideshow by adding following JavaScript codes within <script> tag.


    // LIST OF CAPTİONS  

    caption[0] = "Caption for the first image";

    caption[1] = "Caption for the second image";

    caption[2] = "Caption for the third image";

    function swapImage(){

    var el = document.getElementById("mydiv");

    el.innerHTML=caption[i];

    var img= document.getElementById("anim1");

    img.src= image[i];

    if(i <k ) { i++;}

    else { i = 0; }



    For details on adding caption on image slideshow visit the post: How To Create Simple Image Slideshow Using JavaScript ?


    Fade effect image slideshow with caption and link


    You can add caption for this slideshow by adding following JavaScript codes within <script> tag.



    var link= new Array();   

    link[0] = "http://www.siteforinfotech.com/";
    link[1] = "http://www.siteforinfotech.com/p/tutorial.html";
    link[2] = "http://www.siteforinfotech.com/p/mcqs.html";


    function swapImage(){

    var el = document.getElementById("mydiv");

    el.innerHTML=caption[i];

    var img= document.getElementById("anim1");

    img.src= image[i];

    var a = document.getElementById("link");
    a.href= link[i];

    if(i <k ) { i++;}

    else { i = 0; }



    For details on adding caption and link on image slideshow visit the post: How to Create JavaScript Image Slideshow with Links



    Related Posts:

    How to make rounded corners border using CSS


    While designing website, website template or blog template, you may want to make buttons, menus, paragraphs or any others border corners rounded to make your template more beautiful and attractive. It is possible by using a keyword "border-radius" in CSS. The keyword border-radius is used to make all the corners rounded by specifying the radius of corner. For example you can use the following CSS code.
    rounded corners border using CSS

    border-radius:10px;                    // makes radius of all the corners 10px;

    You can also specify the radius for each corners by using border-radius-top-right, border-radius-top-left, border-radius-bottom-right, border-radius-bottom-left keywords. For example you can use the following CSS code to make each corner rounded.

    border-radius-top-right:10px;
    border-radius-top-left:10px;
    border-radius-bottom-right:5px;
    border-radius-bottom-left:5px;

    The above code makes radius of left and right corners of top side 10px and radius of left and right corners of bottom side 5px.

    To makes this CSS code browser specific or specific browser compatible, you have to use the prefix codes like -moz- for mozilla firefox and -webkit- for chrome or safari.


    .all{

    border:2px solid red;

    -moz-border-radius:10px;

    -webkit-border-radius:10px;

    border-radius:10px;

    width:250px;

    }

    .topleft{

    border:2px solid red;

    -moz-border-top-left-radius:10px;

    -webkit-border-top-left-radius:10px;

    border-top-left-radius:10px;

    width:250px;

    }

    .topright{

    border:2px solid red;

    -moz-border-top-right-radius:10px;

    -webkit-border-top-right-radius:10px;

    border-top-right-radius:10px;

    width:250px;

    }

    .bottomleft{

    border:2px solid red;

    -moz-border-bottom-left-radius:10px;

    -webkit-border-top-left-radius:10px;

    border-bottom-left-radius:10px;

    width:250px;

    }

    .bottomright{

    border:2px solid red;

    -moz-border-bottom-right-radius:10px;

    -webkit-border-bottom-right-radius:10px;

    border-bottom-right-radius:10px;

    width:250px;

    }


    Use above CSS code with the following HTML code given.

    <html>
    <head>
    <title>CSS code for rounded corners</title>
    <style type="text/css">

    //place the abobe CSS code

    </style>
    </head>
    <body>
    <div class="all">All rounded corners</div>
    </br>
    <div class="topleft">Topleft rounded corner</div>
    <br/>
    <div class="topright">Topright rounded corner</div>
    </br>
    <div class="bottomleft">Bottomleft rounded corner</div>
    <br/>
    <div class="bottomright">Bottomright rounded corner</div>
    </body>
    </html>

    You can view the following rounded corners for 2px solid red border and 250px width having 10px radius of corners.


    All rounded corners

    Topleft rounded corner

    Topright rounded corner

    Bottomleft rounded corner

    Bottomright rounded corner


    Here I have used <div> tag, so these shapes are appeared with line break. If you wanted to place these shapes on the same line you can use <span> tag. You can also use <p> tag with the place of <div> tag.

    You can apply these rounded corners shapes to make CSS buttons, menus etc. Here is a sample code to make CSS button along with background color.

    <div style="border:2px solid light-blue; -moz-border-radius:10px;
    background-color:blue; z-index:10;-webkit-border-radius:10px;
    border-radius:10px;width:110px;text-align:center;
    color:white;cursor:pointer;">
    CSS button
    </div>




    Related Posts:



    How to Create Custom CSS Template for Printing


    Along with the development of web technologies and web programming languages, web designing becoming more complex and the websites more flexible and user friendly. With the invention of CSS technology, web designing and programming becoming more easier than ever.

    By using cascading style sheet (CSS) and its properties, you can give custom design to your website for different medias like screen, print, tv and for different screen sizes. The CSS @media property allows you to do such task.

    Today I am going to describe "How to create custom CSS template for printing".

    Designing Custom CSS Template for Printing


    If you wanted to allow your website visitors to print the content of your website, you can design custom template for printing using CSS. You can define which part or your website will be printed or not and can add page setting for printing.

    Designing Custom CSS Template for Printing

    Here is a sample CSS code for website template.


    body{
    background:#00aaff;
    font-color:#00000;
    font-size:16px;
    }

    h1, h2, h3 {

    /* CSS codes for h1, h2, h3 */

    }

    #wrapper{
    width:80%;
    margin: 0 auto;
    background:#fff;
    padding:20px;
    }

    #content{
    width:54%;
    float:left;
    margin-right:3%;
    }

    #header{
    width:100%;
    margin-top:2%;
    }

    #sidebar-left{
    width:20%;
    float:left:
    margin-right:3%;
    }

    #sidebar-right{
    width:20%;
    float:left;
    }

    #footer{
    width:100%;
    }


    While printing you can hide default header, menu and sidebar using CSS codes. Here is a sample CSS code for printing webpage.


    body{
    background:#00aaff;
    font-color:#00000;
    font-size:16px;
    }

    h1, h2, h3 {

    /* CSS codes for h1, h2, h3 */

    }

    #wrapper{
    width:80%;
    margin: 0 auto;
    background:#fff;
    padding:20px;
    }

    #header{
    display:none;
    }


    #content{
    width:100%;
    clear:both;
    margin-right:3%;
    }

    #sidebar-left{
    display:none;
    }

    #sidebar-right{
    display:none;
    }

    #footer{
    display:none;
    }


    Place the above CSS code inside media queries for printing as below.

    @media only print and (orientation:portrait) { 
        
         /* Add CSS code here for printing on portrait mode */
     }

    @media only print and (orientation:landscape) { 
        
         /* Add CSS code here for printing on landscape mode */
     }



    Adding Printing function and icon



    Add the following HTML code where you want to place print icon.

    <a href="javascript:window.print()"> Print this page </a>

    Using this code the print link looks like as below                                     Print this page


    <a href="javascript:window.print()"> <img src="print.jpg"></a>

    Print
    Using this code the print icon looks like as below


    <form><input type="button" value="Print This" onclick="window.print()"></form>

    Using this code the print button looks like as below                                                            



    Related Posts: