Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Friday, 20 February 2015

How to set value of one textbox to another on checkbox checked ?

Permanent address is same as Current address on checkbox click Javascript code.

Html Code:

<form method="post" >

    <input type="text" name="currentaddress" id="currentaddress" placeholder="Current Address" /><br>

    <input type="checkbox" onClick="return address()" name="accept" id="accept"><label for="accept">Same As Above<label><br>

    <input type="text" name="permanentaddress" id="permanentaddress"  placeholder="Permanent Address" />

</form>


Javascipt code:

(Copy-paste the following code in head section of your html page)

function address()
    {
        var chk=document.getElementById("accept").checked;
        if(chk)
        {
        var a1=document.getElementById("currentaddress").value;
        //alert(""+a1);
        document.getElementById("permanentaddress").value=a1;
        document.getElementById("permanentaddress").disabled=true;
        }
        else
        {
            document.getElementById("permanentaddress").disabled=false;
        }
    }

Live Demo