Home > Software design >  Update Content based on drop down selection
Update Content based on drop down selection

Time:04-23

Okay, So basically I have a WP plugin. In this plugin there is a ton of logic like below...

then below all that it does a loop for posts and outputs data based on them etc..

All I want to do is be able to change the monday date to be a different date based on a drop down selection. However, I do not want to reload the page every time.. But with Ajax I can not change variable that have already loaded on a page. How do I update Mondate to be a new value based on the value of a drop down selection.

 echo '<select name="donewithit" style="border:solid 1px;" id="myDropDown">
    <option value="1">This Week</option>
    <option value="3">Last Week</option>
    <option value="2">Next Week</option>
 </select>';
$mondate = date('Y-m-d', strtotime(' 1 Monday'));
        $today = date('Y-m-d');
        $todayday = date("l");

        if ($mondate != $today && $todayday == "Monday") {
            $mondate = $today;
        }
        $tusdate = date('Y-m-d', strtotime($mondate . '   1 days'));
        $weddate = date('Y-m-d', strtotime($mondate . '   2 days'));
        $thusdate = date('Y-m-d', strtotime($mondate . '   3 days'));
        $fridate = date('Y-m-d', strtotime($mondate . '   4 days'));
    echo $mondate;
        for ($i = 0; $i < 5; $i  ) {
            // get year, month, and day
            if ($i == 0) {
                $year =  date("Y", strtotime($mondate));
                $month =  date("m", strtotime($mondate));
                $day =  date("d", strtotime($mondate));
                $displayday = "MON";
            } else if ($i == 1) {
                $year =  date("Y", strtotime($tusdate));
                $month =  date("m", strtotime($tusdate));
                $day =  date("d", strtotime($tusdate));
                $displayday = "TUE";
            } else if ($i == 2) {
                $year =  date("Y", strtotime($weddate));
                $month =  date("m", strtotime($weddate));
                $day =  date("d", strtotime($weddate));
                $displayday = "WED";
            } else if ($i == 3) {
                $year =  date("Y", strtotime($thusdate));
                $month =  date("m", strtotime($thusdate));
                $day =  date("d", strtotime($thusdate));
                $displayday = "THU";
            } else if ($i == 4) {
                $year =  date("Y", strtotime($fridate));
                $month =  date("m", strtotime($fridate));
                $day =  date("d", strtotime($fridate));
                $displayday = "FRI";
            }

CodePudding user response:

Basically,

Had to duplicate this functionality three times and then hide the versions I did not want to show via javascript which is executed on a drop down select menu.

not ideal. not what I wanted. Only solution I could think of.

  • Related