Tuesday 5 April 2016

How to set or get textbox value using Javascript or Jquery ?

Introduction:

Here I will explain How to set textbox value using Jquery, How to get textbox value using Jquery, How to set textbox value using Javascript, How to get textbox value using Javascript. If you want to How to set or get textbox value using Javascript or Jquery then copy following code in your page.

Description: 

In previously post I explained to  
file type validation in jquery
Change the column name or datatype or size in sql server
How to set or get textbox value using Javascript or Jquery
Server does not support secure connections  
textbox allow only characters javascript
button click event not firing in asp.net c#

And now here I explain to How to set textbox value using Jquery, How to get textbox value using Jquery, How to set textbox value using Javascript, How to get textbox value using Javascript in asp.net.

Now copy the one by one following javascript code in your page.


How to set or get textbox value using Javascript or Jquery ?

How to set textbox value using Javascript


function setValueJavascript() {
        document.getElementById('txtName').value = "Set Value To textbox using javascript";
    }

How to get textbox value using Javascript

function getValueJavascript() {
        var Name = document.getElementById('txtName').value;
        alert(Name);
    }

How to set textbox value using Jquery

function setValueJquery() {
        $("#txtName").val('Set Value To textbox using Jquery');
    }

How to get textbox value using Jquery

function getValueJquery() {
        var Name = $("#txtName").val();
        alert(Name);
    }

Here full example of How to set textbox value using Javascript, How to get textbox value using Javascript How to set textbox value using Jquery and How to get textbox value using Jquery

Example:


<!DOCTYPE html>
<html>
<head>
    <title>How to set or get textbox value using Javascript or Jquery</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js">
    </script>
    
    <script>

    function setValueJavascript() {
        document.getElementById('txtName').value = "Set Value To textbox using javascript";
    }

    function getValueJavascript() {
        var Name = document.getElementById('txtName').value;
        alert(Name);
    }

    function setValueJquery() {
        $("#txtName").val('Set Value To textbox using Jquery');
    }

    function getValueJquery() {
        var Name = $("#txtName").val();
        alert(Name);
    }
    </script>
</head>
<body>
    <h1>How to set or get textbox value using Javascript or Jquery</h1>

    Enter Name: <input type="text" id="txtName" />

    <br /><br />
    <input type="button" value="Set Value Javascript" onclick="setValueJavascript()" />
    <input type="button" value="Get Value Javascript" onclick="getValueJavascript()" />
    <input type="button" value="Set Value Jquery" onclick="setValueJquery()" />
    <input type="button" value="Get Value Jquery" onclick="getValueJquery()" />
</body>
</html>

How to get Value of All textbox of particalar Div

Some times required to get Value of All textbox of particalar Div and inserting or doing some operation to these texboxes value. so I have added this complete code to get Value of All textbox of particalar Div or get Value of multiple textbox of particalar Div using Jquery.

Example:


<!DOCTYPE html>
<html>
<head>
    <title>How to get Value of All textbox of particalar Div</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js">
    </script>

    <script>
        function GetValue() {
            var Contain = "";
            $("#divRegsiter :text").each(function () {
                alert($(this).val());
            });
        }
    </script>
</head>
<body>
    <h1>How to get Value of All textbox of Div</h1>

    <div id="divRegsiter">
        Enter Name: <input type="text" id="txtName" /><br />
        Enter User Name: <input type="text" id="txtUserName" /><br />
        Enter Email: <input type="text" id="txtEmail" /><br />
    </div>
    <div id="divLogin">
        <p>Not getting this textbox value when you click on button, because 
        this is exist in different Div</p>

        Enter Name: <input type="text" id="txtNameLogin" /><br />
    </div>
    <br /><br />
    <input type="button" value="Get All Textboxes Value" onclick="GetValue()" />
</body>
</html>

No comments:

Post a Comment



Asp.net tutorials