Tuesday 13 February 2018

Validate File Size Spell Upload Amongst The Help Of Javascript

This ship service shows how to validate the file spell upload the data. While uploading the information it checks the validation similar the file size should move less too then 2MB too you lot too validate  the format of the file. Here i checking the file size should move less too then 2MB. If the size should move to a greater extent than than 2mb it shows the mistake "File size is grater than 2mb.Please upload the file below 2mb." Like that.

This is the script to validate the file spell upload:

<script>
business office validate() {
$("#file_error").html("");
$(".inputbox1").css("border-color","#F0F0F0");
var file_size = $('#file')[0].files[0].size;
if(file_size>2097152) {
$("#file_error").html("File size is greater than 2MB. Please upload file below 2MB.");
$(".inputbox1").css("border-color","#FF0000");
supply false;
supply true;
}
</script>

It showing crimson edge inward the text box too given the mistake message below the text box  when validation mistake occurs. Please Check the demo page to banking company friction match this example. This is i of the really useful concept for the programmers. I promise this is really useful.

Code for Validate File on Upload:

<html>
<head>
<style>
#filesizeval {width:500px; margin:0 auto;    border: #050505 2px solid;
background: #F1F0F0;padding:80px; }
.inputbox1{
padding:10px;    
margin: 0 auto;display: 
block;     
border: 1px company #A39F9F; 
border-radius:4px;
background-color:#FFF;
}
#file_error
{
color: #FF0000;
}
#button
{
background-color:#2FC332;
margin: 23px auto;
display: block; 
border:0;
padding:10px 40px; 
color:#FFF;
border:#F0F0F0 1px solid; 
border-radius:4px;
}
</style>
<script src="http://code.jquery.com/jquery-2.1.1.js"></script>
<script>
business office validate() {
$("#file_error").html("");
$(".inputbox1").css("border-color","#F0F0F0");
var file_size = $('#file')[0].files[0].size;
if(file_size>2097152) {
$("#file_error").html("File size is greater than 2MB. Please upload file below 2MB.");
$(".inputbox1").css("border-color","#FF0000");
supply false;
supply true;
}
</script>
</head>
<body>
<form name="filesizeval" id="filesizeval" method="post" action=""  onSubmit="return validate();">
<div><input type="file" name="file" id="file" class="inputbox1" /> <br/><center><span id="file_error"></span></center></div>
<div><input type="submit" id="button" value="Upload"/></div><br/><br/>
<center><a style="color: #000; font-weight: bold; font-size: 17px;" href="http://www.sanwebcorner.com">www.sanwebcorner.com</a></center>
</form>
</body>
</html>

SHARE THIS

Author:

Just a regular website is not the website of incredible, but not also means the site is not responsible for all of what is in it, in this case the Admin, who manages this site fully responsible to what-what is published in it.

0 comments: