PrepAway - Latest Free Exam Questions & Answers

You develop an HTML5 webpage. You have the following HTML markup:

You develop an HTML5 webpage. You have the following HTML markup:

<

input type=-text- id=-username- /

>

You need to prevent users from entering specific characters into the username field.

What should you do?

A. Using the keyup event, add an anonymous function that returns true when a specific character keycode value is determined.

B. Using the change event, add an anonymous function that returns true when a specific character keycode value is determined.

C. Using the keydown event, add an anonymous function that returns false when a specific character keycode value is determined.

D. Using the change event, add an anonymous function that returns false when a specific character keycode value is determined.

Explanation:

The change event is fired for

<

input

>

,

<

select

>

, and

<

textarea

>

elements when a change to the elements value is committed by the user.

Use the change event and an anonymous function to detect illegal specific characters in the input.

3 Comments on “You develop an HTML5 webpage. You have the following HTML markup:

  1. kaggelpiep says:

    Yes, thought so. Thank you. This was answered wrong in my test exam, as so many questions. This is causing so much confusion since you are starting to doubt your own correct thoughts, which can cause more errors and confusion with other questions.




    0



    0
  2. _mr says:

    Agree – C is correct.

    Code:

    $(function() {
    $(“#username”).keydown(validateUsername); // Correct.
    //$(“#username”).keyup(validateUsername); // Does not prevent from input forbidden character ‘A’.
    //$(“#username”).change(validateUsername); // Does not trigger when typing.
    });

    function validateUsername(e) {
    if (e.keyCode == 65) {
    alert(“Forbidden character pressed.”);

    return false;
    }

    return true;
    }




    0



    0

Leave a Reply