How to find any word in Textarea by JS ? | SoloLearn: Learn to code for FREE!

+30

How to find any word in Textarea by JS ?

Can someone plz help me how to find any word by JS ? Example : Textarea : I Love JavaScript & It's Very Intresting Language User Input : JavaScript or (Any word) Output : if word found then alert Alert ("Found Word "); else; Alert ("Not Found Word "); https://code.sololearn.com/WyyD61sS4GvH/?ref=app

8/13/2020 7:40:00 AM

Prachi The Pari🎸 [ Inactive ]

18 Answers

New Answer

+14

di aap string handling search kijye google pe vaha aapko mil jayga ki how to handle strings in Js https://code.sololearn.com/WtCWNfqm2iUT/?ref=app Di analize it

+17

Thank you so much 🤗 UmV6YQ== & Bugs & Namit Jain & Darshan Raval or Akash Kumar Srivastava Here are 4 answer helped me

+16

Use includes method if (textarea.value.includes(word)) { alert("found"); } else { alert("not found"); }

+16

Prachi The Pari💕 I complete the function https://code.sololearn.com/WBURla10lS5e/?ref=app

+16

Prachi The Pari💕 ur welcome :)

+13

Geekyorion Thank you so much it's also helping 🤗

+11

iamSamaritan Wow that's great idea Thank you so much 😀👍

+9

First target your id var str = document.getElementbyId('idname').value Now you can use the search function / method var sch = str.search(any_word) If (sch != -1 ) alert( "word found" ) else alert("Not found") Hope this helps !!

+7

To find a word you can use the syntax "indexOf" it is -1 when the word is not there in the text Try to type "namit jain" https://code.sololearn.com/WxIHZrMD0q5x/?ref=app

+7

Prachi The Pari💕 Hehe 👦💃💃

+6

👇👇👇Try this 👇👇👇 function search(){ var str = 'My name is akash kumar srivastava'; var search = prompt("Enter your string to search ","akash"); var pos = str.indexOf(search); if(pos>0){ alert ("Found") } else { alert ("Not found") } }

+6

https://code.sololearn.com/WjxXfVJmMDRn/?ref=app

+5

Anytime

+3

Why don't you use regex match and can do this in a very less line of code. if you want, I can share the code

+3

https://code.sololearn.com/W3eHB44kiafX/?ref=app Add items and start searching below.. Not that you'll do first search and get a message saying "match found" then maybe add more items and when you search / repeat the first search ... Wrong message will be displayed "scope confusion" But code is correct as found item / items will remain displayed while not found will disappear.. 👌.. You use search method but in that example indexOf() had be used..

+1

Mamá culo

+1

indexOf is the easiest way, but might not be the fastest way. Why isn't indexOf working for you? You will get the index of the match, and you know the length of the match, so just highlight the text that matched.

+1

u can use var textarea = document.queryselector("textarea").textContent; if textarea.includes(userinput) alert(msg); else somthing explanation:- 1 --> in first line we have created a variable and stored the text from the textarea inside that variable. 2 --> next we have used a JS inbuilt string method ( string.includes(parameter) ) that will find the word we r providing it as a parameter. 3 --> if the value present in the text it will be true else false.