Home How can I store the text entered into a html textarea into a javascript variable?
Reply: 3

How can I store the text entered into a html textarea into a javascript variable?

Iñaki
1#
Iñaki Published in 2017-12-05 10:49:49Z

This question already has an answer here:

  • jQuery get textarea text 7 answers

I want to store the text users enter into a textarea in a website into a javascript variable in order to compare it to another variable already defined.

How would you do it? Any hints? Thanks in advance!

Vipin Kumar
2#
Vipin Kumar Reply to 2017-12-05 10:52:05Z

Use following code

var textareaValue = document.getElementById('textAreadID').value

Replace textAreadID with your textarea id.

Brainfeeder
3#
Brainfeeder Reply to 2017-12-05 10:52:41Z

In jQuery:

var str = "compare with me",
value = $('textarea[name="yourareaname"]').val();

if(str == value) {
    alert('hell yeah');
}
Deepu Reghunath
4#
Deepu Reghunath Reply to 2017-12-05 10:54:07Z

using jquery

var n=$('#textarea_id').val();

using javascript

var n=document.getElementById('textAreaID').value;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.344748 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO