The below are the 2 different approaches for getting or setting the value of the text input field:
Using text value property: The text value property is used to set or return the value of a value attribute of the input field. The value attribute specifies the initial value of the Input Text Field. It contains the default value or the user types.
Get value : textObject.value Set value : textObject.value = text
Example 1: This example uses the Text value property to get the value from the input text field.
Using jquery val() method: The val() method is used to return or set the value attribute of the selected elements. In default mode, this method returns the value of the value attribute of the FIRST matched element & sets the value of the value attribute for ALL matched elements.
Get value : $(selector).val() Set value : $(selector).val(value)
Example 2: This example describes the jquery val() method to fetch the values from the input field.