DEV Community

John Ellee Robado
John Ellee Robado

Posted on • Edited on

2

Drop Down List Category(Daily, Weekly, Yearly) with search box using HTML, jQuery and PHP

Drop Down List Category(Daily, Weekly, Yearly) with search box using jQuery with PHP

So today, I will teach you how you do it

HTML, first you create a drop down list and two textbox


Daily
Weekly
Monthly
Search (Slow Search)

To

jQuery code

$(document).ready(function(){
$(".category").change(function(){
if($(".category option:selected").val()=="4"){
$(".date1").fadeIn();
$(".label_to").fadeIn();
$(".date2").fadeIn();
}
else{
$(".date1").fadeOut();
$(".label_to").fadeOut();
$(".date2").fadeOut();

}
});
)};

PHP Code

<?php
//Declare variable
$date1;
$date2;

//Set Timezone
date_default_timezone_set("America/New_York");
//Daily
if($_POST['category']==1){
$date1=date("Y-m-d");
$date2=date("Y-m-d");
}
//Weekly
if($_POST['category']==2){
$days=array("Monday"=>0,"Tuesday"=>1,"Wednesday"=>2,"Thursday"=>3,"Friday"=>4);
foreach ($days as $key => $value) {
if(date("l")==$key){
$date1=date("Y-m-d",strtotime("-".$value."days"));
$date2=date("Y-m-d",strtotime("+".(4-$value)."days"));
}
}
}
//Monthly
if($_POST['category']==3){
$date1=date("Y-m-1");
$date2=date("Y-m-t");
}
//Yearly
if ($_POST['category']==4) {
$date1=date('Y-01-01');
$date2=date('Y-12-31');
}
//Search
if($_POST['category']==5){
$date1=date("Y-m-d",strtotime($_POST['date1']));
$date2=date("Y-m-d",strtotime($_POST['date2']));
}
?>

Note: You must include this jquery library

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more