You work as a developer at ABC.com. The ABC.com network consists of a single domain named
ABC.com. You make use of CSS3 and HTML5 for development purposes.
You are in the process of creating a new client web form for ABC.com. You have added the HTML
input field shown below:
<input id=”txtValue” type=”text” />
You want to write the appropriate code to make sure that txtValue has a value inserted, prior to the
form being tendered.
Which of the following is the required code?
A.
function validate() {
var name = $(“#txtValue”).val () ;
if (name == null // name == “”)
alert (“please enter valid value”) ;
return;
}
B.
function validate() {
var name = $(“#txtValue”).val ($) ;
if (name == null // name == “”)
alert (“”) ;
}
C.
function validate() {
var name = (“#txtValue”).val ($) ;
alert (“please enter valid value”) ;
}
D.
function validate() {
var name = $().val () ;
if (name == $ // name == “$”)
return;
}
Explanation:
The required attribute within the creation of the input field is the preferred answer instead of a validation function according to HTML5 semantic rules.
”
‘input id=”txtValue” type=”text” required=”required”‘