To retrieve the value of a checkbox, use the checked attribute. Get Value or Selected Option in Select Box Using JavaScript Set the value of an input field in JavaScript - GeeksforGeeks how to get input value by id in javascript Code Example Join thousands online course for free and upgrade your skills with experienced instructor through OneLIB.org (Updated January 2022) The value of the textarea is reset only the first time the textarea field gets focus, by setting its value attribute to the empty string. alert ("The name may have no more than 10 characters"); submitOK = "false"; } if (isNaN (age) || age < 1 || age > 100) {. If the attribute exists on the element, the getAttribute() returns a string that represents the value of the attribute. The second example can be used for setting the value of the property. Covering popular subjects like HTML, CSS, JavaScript, Python, … Return value. If your input is in a form and you want to get value after submit you can do like