Hi Guys,
I have a javascript, which counts the specified words..
I want javascript to count some of the html tags and symbols when i enter a html code in the textarea..
- the below searchwords are not functioning properly.
http://(space)
http:/(space)
etc... (no spaces are searching)
- www. (.(dot) is not searching, also when i enter wwww(4 times) in the textarea it shows www. as count 1)
- i can't enter the below symbols in searchwords array
[
<
'
?
Please help me out guys...
Here is my Code...
[code]
<html>
<head>
<title>Word Count</title>
<script type = "text/javascript">
function searchForWords(){
document.getElementById('resultsContainer').innerHTML = '';
var txt = document.getElementById('txtMsg').value;
var strWords = document.getElementById('txtSearchWords').value;
var searchWordsTokens = strWords.split(' ');
var searchWords = ['href','LINK_ID','mailto','src="','src= ','src =','.jpg','.gif','.png','www','www.','http','http:// ','http:/ ','http: ','http ',' http',' "','@','amp;','TBD'];
for(i=0; i < searchWordsTokens.length; i++){
if(searchWordsTokens[i].length > 0){searchWords.push(searchWordsTokens[i]);} //remove spaces between words
}
var results = [],matches;
for(i=0; i < searchWords.length; i++){
var regex = new RegExp('\\b'+searchWords[i]+'\\b','gi');
matches = txt.match(regex);
results[searchWords[i]] = (matches)? matches.length : 0;
}
//output results
var str = '';
for(var i in results){
str += i+'--'+results[i]+'<br />';
}
document.getElementById('resultsContainer').innerHTML = str;
}
window.onload=function(){
document.getElementById('form_submit').onclick=searchForWords;
}
</script>
</head>
<body>
<table>
<tr><td align="center">
<form id="contact_form"><h4>Paste your HTML Code here:</h4>
<p><label class="form_label" for='message'></label>
<textarea rows="20" cols="60" id="txtMsg"></textarea>
</p>
<div>
<input type="text" id="txtSearchWords"/>
</div>
<p><input id='form_submit' type="button" value="Check for Counts"></p>
<div><p><input id='form_submit' type="reset" value="Clear"></p></div>
<div id="resultsContainer"></div>
</form><br /></td>
</table>
</body>
</html>
[/code]


