Showing posts with label HTML5. Show all posts
Showing posts with label HTML5. Show all posts

Thursday, 22 May 2014

Give custom validation message in HTML5

Custom Message in HTML5

Generally if you are just giving required in input it will give its own validation message in html5. But if you want to give your custom message then do this.

<input id="UserID" type="text" required="required" oninvalid="this.setCustomValidity('Witinnovation')">

Wednesday, 13 November 2013

Thursday, 12 September 2013

Store array in LocalStorage (HTML5)

Sometimes we need to store an array at client side so the best way to store array in localstorage just like temp storage container. So here is code.

localStorage only supports strings. Use JSON.stringify() and JSON.parse().
var names = [];
names[0] = prompt("New member name?");
localStorage["names"] = JSON.stringify(names);

//...
var storedNames = JSON.parse(localStorage["names"]);

Saturday, 15 June 2013

Heighlight portion in Image

 
ImageMapster is a jQuery plugin that lets you activate HTML image maps without using Flash. It works just about everywhere that Javascript does, including modern browsers, Internet Explorer 6, and mobile devices like iPads, iPhones and Androids.


You can see online demo http://www.outsharked.com/imagemapster/

In heade tag

 
    
    
  


In html tag
Venus 123
123 123 123 123

Tuesday, 28 May 2013

Validate Forms using HTML5


Step 1. HTML

This is our main source file with our form. I decided to create some ‘Join form’ to website using HTML5:

    
    


General Info
Miscellaneous Info
Male Female
Subscribe to our news
I have read and agreed with Terms of Use.
Here are important notes. HTML5 using several new attributes as rules for validation of form fields. This is:
  • required – this attribute will transform field into required field. This attribute applicable to different form elements (input, select, textarea etc). So if we will mark our field with this attribute, it will mean that we will need to check our checkbox field, type value for text field, select value from selector etc.
  • pattern – this attribute will determinate regular expression which will using for checking values of elements. In our example I will use this attribute to set custom pattern for email and phone fields.
  • maxlength – we can use this attribute to set max limit of symbols for field


Step 2. CSS

All styles here:

css/main.css

body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.example{background:#FFF;width:700px;font-size:80%;border:1px #000 solid;margin:10px auto;padding:1em 2em 2em;-moz-border-radius: 3px;-webkit-border-radius: 3px}

form{font-size:100%;min-width:560px;max-width:620px;width:590px;margin:0 auto;padding:0}
form fieldset{clear:both;font-size:100%;border-color:#000;border-style:solid none none;border-width:1px 0 0;margin:0;padding:10px}
form fieldset legend{font-size:150%;font-weight:400;color:#000;margin:0;padding:0 5px}
label{font-size:100%}
label u{font-style:normal;text-decoration:underline}
input,select,textarea{font-family:Tahoma, Arial, sans-serif;font-size:100%;color:#000}
textarea{overflow:auto}
form div{clear:left;display:block;width:354px;zoom:1;margin:10px 0 0;padding:1px 3px}
form div fieldset{clear:none;width:197px;border-color:#666;border-style:solid;border-width:1px;margin:0 0 0 144px;padding:0 5px 5px}
form div fieldset legend{font-size:100%;padding:0 3px 0 9px}
form div label{display:block;float:left;width:130px;text-align:right;margin:0 0 5px;padding:3px 5px}
form div.optional label,label.optional{font-weight:400}
form div img{float:left;border:1px solid #000;margin:0 0 5px}
form div input.inputFile{width:211px}
form div.submit{width:214px;padding:0 0 0 146px}
form div.submit div{display:inline;float:left;text-align:left;width:auto;margin:0;padding:0}
form div.required fieldset legend,form div.required label,label.required{font-weight:700}
form div select,form div textarea,form div input.inputText,form div input.inputPassword{width:200px;margin:0;padding:1px 3px}

:valid {box-shadow:  0 0 5px green}
:-moz-submit-invalid {box-shadow:  0 0 5px pink}

 

Step 3. JS

We will using one easy function for password validation in this file

js/main.js

function validatePass(p1, p2) {
    if (p1.value != p2.value || p1.value == '' || p2.value == '') {
        p2.setCustomValidity('Password incorrect');
    } else {
        p2.setCustomValidity('');
    }
}
Reference site : http://www.script-tutorials.com/data-validation-html5/

Monday, 13 May 2013

HTML5 multiple fileupload

For Client side


HTML design view
  
  
Script for this



For Server side

HTML design view
 
 
  
Server side code for this
protected void btnUpload_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                Request.Files[i].SaveAs(Server.MapPath("Uploaded") + "/" + Request.Files[i].FileName);
            }
        }