+ 62
How to find any word in Textarea by JS ? [ Solved! ]
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
18 Réponses
+ 17
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
+ 28
Thank you so much 🤗 UmV6YQ== & Bugs & Namit Jain & Darshan Raval or Akash Kumar Srivastava
Here are 4 answer helped me
+ 19
Prachi The Pari💕 ur welcome :)
+ 19
Geekyorion Thank you so much it's also helping 🤗
+ 19
iamSamaritan Wow that's great idea Thank you so much 😀👍
+ 18
Prachi The Pari💕
I complete the function
https://code.sololearn.com/WBURla10lS5e/?ref=app
+ 17
Use includes method
if (textarea.value.includes(word))
{
alert("found");
} else {
alert("not found");
}
+ 10
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 !!
+ 8
Prachi The Pari💕 Hehe 👦💃💃
+ 7
👇👇👇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
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
+ 6
Anytime
+ 4
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
+ 4
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..
+ 2
Mamá culo
+ 2
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.
+ 2
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.