0

I have a function that gets the birthdate and don't print the output which is the sign according to the birthdate

I want the output to be under the send button (where id=output) currently works only with alert

another possibility is that the output will be in an input text.

Do you have any solution instead of alert as an output?

function yourSign() {
    var signDate = $("input[name='birthDate']").val();
    tempSignDate = signDate.split("-").join("/");
    newSignDate = tempSignDate.substring(5, 10);
    var AriesDateFrom = "21/03";
    var AriesDateTo = "20/04";
    var TaurusDateFrom = "21/04";
    var TaurusDateTo = "20/05";
    var Ad1 = AriesDateFrom.split("/");
    var Ad2 = AriesDateTo.split("/");
    var Td1 = TaurusDateFrom.split("/");
    var Td2 = TaurusDateTo.split("/");
    var s = newSignDate.split("/");
    if (newSignDate == "") {
        alert("enter birthday");
    }else if (s >= Ad1 && s < Ad2) {
         document.getElementById("output").innerHTML = "Aries";
     }else if (s >= Td1 && s < Td2) {
         document.getElementById("output").innerHTML = "Taurus";
     }
}
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <head>
        <meta charset="utf-8" /> 
        <!--<script src="https://code.jquery.com/jquery-1.12.4.min.js"
                integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
                crossorigin="anonymous">
        </script>-->
        </head>
            <body>
            <div>
                <form>
                <label for=birthDate>birthdate</label><br /><input type="date" name="birthDate" id="birthDate" /><br />
                <button onclick="yourSign()">send</button><br />
                <label> your sign is </label><br />
                <p id="output"></p>
                <!--<input type="text" name="output" id="output" />-->
            </form>
        </div>
    </body>
    </html>
freedomn-m
  • 27,664
  • 8
  • 35
  • 57
ladyd
  • 37
  • 1
  • 10

1 Answers1

0

split() creates an array. You can not directly compare arrays as a whole.

Your arrays has two elements: day number and month number.

Day is always index 0 in your snippet. Month is always index 1.

Try to compare your arrays in steps:

if ( s[1] >= Ad1[1] && s[0] >= Ad[0] && s[1] <= Ad2[1] && s[0] <= Ad2[0]) { [...] };