Tuesday, 2 August 2016

File Upload Validation using javascript

Below are the script by which you can validate file when you upload
Make the form
<form>
<div class=”form-level“>Upload Resume
<input name=”image” type=”file” id=”upload_resume” placeholder=”Upload Resume”class=”form-control” /></div>
</form>
var fup = document.getElementById('upload_resume'); 
var fileName = fup.value;
var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
if(ext == "doc" || ext == "docx")
{
return true;
}
else
{
alert("Please select your Resume. Only pdf, doc and docx files are accepted");
fup.value="";
fup.focus();
return false;
}
}

3rd Highest Salary from employee table

SELECT * FROM employee one1 WHERE ( 3 ) = ( SELECT COUNT( one2.emp_salary ) FROM employee one2 WHERE one2.emp_salary >= one1.emp_salary )

Redirect to target page by Dropdown List

Redirect to other page by dropdown list :
Step 1: Write down the bit of php code
<?php
if (isset($_POST[‘nav’])) {
 header(“Location: $_POST[nav]”);
}
?>
Step 2: javascript code
<script type=”text/javascript”>
$(function() {
    $(“#submit”).hide();
    $(“#page-changer select”).change(function() {
        window.location = $(“#page-changer select option:selected”).val();
    })
});
</script>
Step 3: Make Html form & fields
<form name=”form1″ id=”page-changer” action=”” method=”post”>
    <div align=”center”><strong>Select Your Option  &nbsp;&nbsp;&nbsp;&nbsp;</strong>
      <select name=”nav”>
  <option value=””>Select Your Option…</option>
  <option value=”paidstp.php”>All Paid Students</option>
  <option value=”paidlocation.php”>Search Date & Location Wise</option>
</select>
      <input type=”submit” value=”Go” id=”submit” />
    </div>
</form>
Untitled

Email ID & mobile number validation in JS

Below are the script by which you can validate email id and mobile number field.
Step 1: Make the form
<div class="form-level">
     <input type="text" class="form-control" name="email" placeholder="Email Id" />
     <span class="form-icon fa fa-envelope"></span>
</div>
<div class="form-level">
      <input name="mobile" placeholder="Enter your Mobile Number" id="mobile" class="form-control" value="" type="text">
      <span class="form-icon fa fa-phone"></span>
</div>

Now apply the below script in your head section

var email = document.fromValidate.email;
var mobile = document.fromValidate.email;
if(email.value==''){
   window.alert('Pleaseer the email id');
   email.focus();
   return false;
}
if(email.value.indexOf('@',0 window.alert('Pleaseer the valid email');
  email.focus();
  return false;
}
if(email.value.indexOf('.',0 window.alert('Pleaseer the valid email');
  email.focus();
  return false;
}
if(mobile.value==''){
  window.alert('Pleaseer the mobile number')
  mobile.focus();
  return false;
}
if(mobile.value.length<10  window.alert('Pleaseer valid mobile number');
  mobile.focus();
}
if(mobile.value.length>10 window.alert('Pleaseer valid mobile number');
 mobile.focus();
}
if(!parseInt(mobile.value)){
  window.alert("Enterts only");
  mobile.focus();
  return false;
}
return true;
}

Fetch the month and year from date where date datatype is datetime

if you want to fetch the records from the below table
Order(varchar)
Order Date(datetime)
 1502014-09-26 10:36:18
 1500 2014-08-26 09:36:18
 5200 2014-06-26 01:36:18
 352 2014-09-26 22:36:18
 8654 2014-05-26 20:36:18
 2554 2014-09-26 14:36:18
 780 2014-03-26 18:36:18
 1200 2014-09-26 15:36:18
Ques: Find out Total amount and month name of order in the Sep 2015
QUERY: SELECT SUM( total ) , month( date_added ) FROM `order` WHERE month( date_added ) =9
OUTPUT: 
Order
month
 4256   9