Home » » Get textarea value in jquery from form

Get textarea value in jquery from form

Written By Unknown on Kamis, 17 Oktober 2013 | 05.09

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>
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger