Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  42] [ 7]  / answers: 1 / hits: 35946  / 11 Years ago, thu, january 2, 2014, 12:00:00

how can I get the contents of span ?
I'm looking for a way for all of this to be vanilla, not jQuery



javascript (and a little jQuery)



var swear_words_arr=new Array(bad,evil,freak);
var regex = new RegExp('\b(' + swear_words_arr.join('|') + ')\b', 'i' );

function validate_user_text() {
var text = document.getElementById('myInput');
text.text();

if(regex.test(text)) {
window.location=http://www.newlocation.com;
return false;
}

}
var myVar=setInterval(function(){validate_user_text()},1000);change


here's my html



<div id=textArea>
<span id=myInput contenteditable=true>kfjdkfj</span>
</div>
<br />
<form name=form1 method=post action=>

<textarea rows=3 cols=40 name=user_text style=border:2 solid #808080; font-family:verdana,arial,helvetica; font-weight:normal; font-size:10pt onclick=select_area()></textarea>
<br />
<input type=button value=Submit onclick=return validate_user_text();></form>


Thank You


More From » jquery

 Answers
22

Give this a shot:



var input = document.getElementById(myInput);
var text = input.innerHTML;

[#73437] Tuesday, December 31, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
juliettec

Total Points: 327
Total Questions: 127
Total Answers: 102

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
;