Update text field with zodiac after choose birthdate

Viewed 44

I have a form with a date field where I choose the user birthdate (dob).

<input type="date" max="2098-12-31" name="meta[dob]" id="meta[dob]" size="25" value="<?php echo $meta['dob'] ? $meta['dob'] : ''; ?>">

What I need to achieve is to update the input zodiac sign right after I enter the birthdate AND before I save the form.

This is my code to find the zodiac sign of the user:

<?php
    $time  = strtotime($meta['dob']);
    $day   = date('d',$time);
    $month = date('m',$time);
    $year  = date('Y',$time);
    if(($month==1 && $day>20)||($month==2 && $day<20)) { $mysign = "aquarius";}
    elseif(($month==2 && $day>18 )||($month==3 && $day<21)) { $mysign = "pisces";}
    elseif(($month==3 && $day>20)||($month==4 && $day<21)) { $mysign = "aries";}
    elseif(($month==4 && $day>20)||($month==5 && $day<22)) { $mysign = "taurus";}
    elseif(($month==5 && $day>21)||($month==6 && $day<22)) { $mysign = "gemini";}
    elseif(($month==6 && $day>21)||($month==7 && $day<24)) { $mysign = "cancer";}
    elseif(($month==7 && $day>23)||($month==8 && $day<24)) { $mysign = "leo";}
    elseif(($month==8 && $day>23)||($month==9 && $day<24)) { $mysign = "virgo";}
    elseif(($month==9 && $day>23)||($month==10 && $day<24)) { $mysign = "libra";}
    elseif(($month==10 && $day>23)||($month==11 && $day<23)) { $mysign = "scorpio";}
    elseif(($month==11 && $day>22)||($month==12 && $day<23)) { $mysign = "sagittarius";}
    elseif(($month==12 && $day>22)||($month==1 && $day<21)) { $mysign = "capricorn";}
?>

How can I update this, right after I choose the user birthdate (dob) in the date field above?

<input type="text" name="meta[zodiac]" id="meta[zodiac]" size="25" value="<?php echo $meta['zodiac'] ? $meta['zodiac'] : ''; ?>">
0 Answers
Related