How to access the value of a textbox using JavaScript?

Answer

Code
<!DOCTYPE html>
<html>
<body>
Full name: <input type="text" id="txtFullName" 
name="FirstName" value="Vikas Ahlawat">
</body>
</html>

There are following ways to access the value of the above textbox:

var name = document.getElementById('txtFullName').value;

alert(name);

or:

we can use the old way:

document.forms[0].mybutton.

var name = document.forms[0].FirstName.value;

alert(name);

Note: This uses the "name" attribute of the element to locate it.

All javascript Questions

Ask your interview questions on javascript

Write Your comment or Questions if you want the answers on javascript from javascript Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---