exam questions

Exam 70-480 All Questions

View all questions & answers for the 70-480 exam

Exam 70-480 topic 4 question 30 discussion

Actual exam question from Microsoft's 70-480
Question #: 30
Topic #: 4
[All 70-480 Questions]

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.
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️
The change event is fired for <input>, <select>, and <textarea> elements when a change to the element's value is committed by the user.
Use the change event and an anonymous function to detect illegal specific characters in the input.

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
RubyH
Highly Voted 4 years, 9 months ago
C is the correct answer -> see https://jsfiddle.net/5f68gcrn/1/
upvoted 8 times
...
Dreamchaser1980
Most Recent 3 years, 11 months ago
You can use keydown event to prevent unwanted chars being entered as illustrated below. document.getElementById("username").addEventListener("keydown", function(e) { if(e.code === "KeyA") { e.preventDefault(); return false; } else { return true; } });
upvoted 1 times
...
nlb
4 years, 4 months ago
Keyup/keydown won't work on input element. So by default A,C are wrong.
upvoted 1 times
Nicolaas
4 years ago
That would be incorrect, The keyup/keydown event is sent to an element when the user releases a key on the keyboard. It can be attached to any element, but the event is only sent to the element that has the focus, And the change event is not necessarily fired for each alteration to an element's value. Meaning it can't be B or D the answer should be A.
upvoted 1 times
...
...
ruif90
4 years, 4 months ago
I guess the right answer is C
upvoted 1 times
...
Shiras
4 years, 11 months ago
option A is most suitable answer, since the data is checked on every keyup event
upvoted 2 times
...
bdb1993
5 years ago
The change event doesn't trigger when you type. Only when it loses focus so the keycode will be undefined
upvoted 2 times
...
Mushi
5 years, 8 months ago
C is the correct answer as returned false from change event will not remove the entered invalid char.
upvoted 2 times
mogec39
5 years, 2 months ago
but if to do "copy+paste" keydown will not be called
upvoted 3 times
mogec39
5 years, 2 months ago
do with the mouse
upvoted 1 times
...
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago