Applied JavaScript Flashcards
The getAttribute() method retrieves the corresponding value of an attribute. What if attribute doesn’t exist?
If the attribute does not exist, an empty string is returned.
Which event handler of the select object specifies the JavaScript code to execute when a user moves the cursor to the select list?
The onfocus event handler of the select object specifies the JavaScript code to execute when a user moves the cursor to the select list.
The hidden element remains unseen to a user on a webpage and while submitting the form. Since it cannot be seen, its value remains unchanged by the user. Although the user can still change the value of a hidden field through the use of browser developer tools.
True
The Safari browser doesn’t support the email and URL objects. The Internet Explorer browser does not support the color object.
True
Which property of the form object returns the number of elements in the form?
length
The length property of the form object returns the number of elements in the form because each form element has a name and a value property.
Which form event handler executes the specified code when the value of an element is modified from the default?
The onchange event handler is used to specify the code to execute when the value of the form element is modified from its default value.
Which event is triggered on the element when the selection is modified?
The onchange event is triggered when a user changes the selection from the default to any other value from the selection list. The event is triggered when the object loses its focus after a selection is made.
Which property is used to control the granularity of the range input type?
The step property of the range input type controls the granularity or the interval between each acceptable values.
Which example shows proper JavaScript syntax for referring to a form object named newForm having a text box named fieldName?
The document interface is the first element that will help to refer the form element through both the form name and the element name, the form object is subordinate to the document object in the JavaScript object hierarchy. So, the correct syntax is:
document.newForm.fieldName.value;
Which of the following expressions will make sure that a user enters a value in the text field before submitting the form?
The document.forms[0].elements[0].required = true; expression adds the required property to the element in the form, which makes sure that a value is entered in the input field before the form can be submitted.
Which event handler of the select object specifies the JavaScript code to execute when the select object loses focus after a user makes a selection, but only if the user selects an option other than the default?
The onchange event handler specifies the JavaScript code to execute when the object loses focus after a user makes a selection, although the change event occurs only if the user changes the selection from the default.
Which of the following protocols is used to protect the user data during transmission?
Secure Sockets Layer (SSL) based transmission makes sure that the data sent between the client and the server is encrypted during transmission, and is not easily eavesdropped by a third party. SSL also prevents the data from being transmitted between the end user and the server from being tampered with or changed.
Which attribute of the file object is used to define the types of files to be uploaded?
The accept property of the file object (input type=”file”) is used to set or return the types of files that will be accepted for upload.
Which method can be used to increase option elements in the select object?
The add() method can be used to append elements to the select object in the options collection.
A user enters confidential data on a website while performing a task. This data was redisplayed on the webpage after the task was completed. The data sent between a server and a browser was not encoded as HTML entities. Which of the following vulnerabilities will occur in the given scenario?
According to the given scenario, the page becomes vulnerable to a non-persistent (reflected) XSS attack. These types of attacks take place when unvalidated user-provided data is included in the HTML page without HTML entities, and received in response from the server. This is the most common type of XSS attack.