Learn how you could easily set a textbox value in Javascript.

As a web developer sometimes you will need to set a textbox value, you can do this when you declare the input textbox element or you can can do it via programming it using Javascript.

In Javascritpt you use this code to set the text value: document.getElementById('txtName').value = "David".

Here's is an example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">


    <title>Javascript: How to set textbox value</title>

    <script type="text/javascript" language="JavaScript">

        function SetTextBoxValue() {

            document.getElementById('txtName').value = "David";





    <h1>Javascript: How to set textbox value Example</h1>


    <input id="txtName" type="text" />

    <button type="button" onclick="Javascript:SetTextBoxValue()">

        Set the Value</button>



Javascript: How to set textbox value Example

Give it a try.

* iOS Development * OS X * Product Review