PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are developing a web form that includes the following HTML.
<input id=”txtValue” type=”text” />
You need to ensure that a value is entered into txtValue before the form is submitted.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
Option A

B.
Option B

C.
Option C

D.
Option D

Explanation:

One Comment on “Which code segment should you use?

  1. Juro says:

    Correct answer is A because:

    1, to get value of an element the $(selector).val() is used (see http://api.jquery.com/val/)
    2, condition in (A) if(name == null || name == “”) checks if name is not null or empty which makes sure that a value has to be entered

    condition in B is more specific and tests whether the value is a number following certain pattern (e.g. 900,200.10) but ALSO EMPTY STRING WILL MATCH THE REGEX




    1



    0

Leave a Reply