Header menu

_________________________________________________________________________________

Thursday, 17 October 2013

Get textarea value in jquery from form

Normally we use val() function with element id to get value of input field of form in jquery ...

But for the case of textarea it doesnt work :(

So to get value of textarea we have to first tell to jquery that we want to access value of textarea.
To do this ..use below code:

var value= $("textarea[id$='textarea-id']").val();

For more detail run below example ::

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
    $( "#b1" ).on("click",function(){
           
            var val=$("textarea[id$='textarea1']").val();
            alert(val);
        });
    $( "#b2" ).on("click",function(){
           
            var val=$("textarea[id$='textarea2']").val();
            alert(val);
        });   
});
</script>
</head>
<body>
Textarea1<textarea id="textarea1"   name="textarea1"></textarea>
<button type="button" id="b1" class="button">Button-1</button></br>
Textarea2<textarea id="textarea2"   name="textarea2"></textarea>

<button type="button" id="b2" class="button">Button-3</button>
</br></br></br>


</body>

</html>

No comments:

Post a Comment