Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

HTML and Javascript help!?

Create a program to check if the month number is greater than 12 then display an error message.

HTML and JavaScript help me with this please!

4 Answers

Relevance
  • Anonymous
    6 years ago

    There. I did your homework for you. Except I used JQuery because it's much nicer.

    https://jsfiddle.net/Leor1txm/

    In short I have an HTML input with the ID month. I select that element based on it's ID, I assign an On Focus Out event so every time you click out of the box it compares the current value to the constraints and displays an alert.

    There's way fancier stuff you can do, but this is the basics.

    EDIT:

    Notice, we don't check against strings. So putting "13abc" in the input field results in nothing happening. I'll leave you to figure out how to check that the value is strictly an integer.

  • 6 years ago

    I'm not going to do it all for you but it seems like you would just use a simple if statement to check the number and if it is greater than 12 you would use an alert box.

    alert("That number is too large!");

    //^displays alert box^:

  • John
    Lv 7
    6 years ago

    <!DOCTYPE html>

    <html lang="en">

    <head>

    <title>validate</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <meta charset="utf-8" />

    <script type="text/javascript">

    function validate(element) {

    var result = true;

    if (element.value > 12 || element.value < 1) {

    alert("Error: invalid month value was entered.");

    result = false;

    }

    return result;

    }

    </script>

    </head>

    <body>

    <input type="number" id="month" onblur="return validate(this);" />

    </body>

    </html>

  • 6 years ago

    Could you please show the coding here also. so that we can see where is the mistake.

Still have questions? Get your answers by asking now.