/    Sign up×
Community /Pin to ProfileBookmark

search method

This script searches for a word that is taken from the window location. But I’m having problems with it, when a all-capital word is searched. Say the letters [COLOR=”Blue”]ABL[/COLOR] are searched, it also counts the word [COLOR=”Blue”]t[COLOR=”Red”]abl[/COLOR]e[/COLOR]. Could someone help me have the search use capital letters as a factor?

[CODE]<script type=”text/javascript”>
function samtals(bi)
{
var ele = document.getElementById(bi);
for(x = 0; x < ele.rows.length; x++)
{
ele.rows[x].className = ‘ah’;
if (x%2 == 0)
{
ele.rows[x].className = ‘ah1’;
}
else
{
ele.rows[x].className = ‘ah2’;
}}}

function rowCount(countWord, elmID){

var table = document.getElementById(elmID);
var rows = table.getElementsByTagName(‘tr’);
var avoid = [0];

function inArray(arr,fval){
for(var i = 0; i < arr.length; i++){
if(arr[i] == fval)
return true;
}
return false;
}

var cellCount = new Array();
for(var i=0;i<rows.length;i++){
var cells = rows[i].getElementsByTagName(‘td’);
for(var x=0;x<cells.length;x++){
var re = new RegExp(countWord,”gi”);
if(cellCount[x] == null){cellCount[x] = 0;}
if(re.exec(cells[x].innerHTML) != null){
cellCount[x] += 1;
}}}

var totalsRow = document.createElement(‘tr’);
for(var i=0;i<cellCount.length;i++){
var td = document.createElement(‘td’);
if (!inArray(avoid,i))
td.innerHTML = cellCount[i];
totalsRow.appendChild(td);
}
totalsRow.className=’countRow’;
table.tBodies[0].appendChild(totalsRow);

}

window.onload = function(){
samtals(‘lideitt_urvalsdeild’);
samtals(‘lidtvo_urvalsdeild’);
samtals(‘lideitt_1_deild’);
samtals(‘lidtvo_1_deild’);
samtals(‘lideitt_bikar’);
samtals(‘lidtvo_bikar’);
var lideitt;
var lidtvo;
if(window.location.search) {
if( lideitt=window.location.search.match(/[?&]lideitt=(w+)/) )
if( lidtvo=window.location.search.match(/[?&]lidtvo=(w+)/) )
var str1=decodeURI(lideitt[1]);
var rts1=str1.replace(/([A-Z])(?=[^A-Z])/g,” $1″);
var utkoma1=rts1.replace(/([^A-Z])([A-Z])/g,”$1 $2″);
var str2=decodeURI(lidtvo[1]);
var rts2=str2.replace(/([A-Z])(?=[^A-Z])/g,” $1″);
var utkoma2=rts2.replace(/([^A-Z])([A-Z])/g,”$1 $2″);
rowCount( utkoma1, ‘lideitt_urvalsdeild’ );
rowCount( utkoma2, ‘lidtvo_urvalsdeild’ );
rowCount( utkoma1, ‘lideitt_1_deild’ );
rowCount( utkoma2, ‘lidtvo_1_deild’ );
rowCount( utkoma1, ‘lideitt_bikar’ );
rowCount( utkoma2, ‘lidtvo_bikar’ );
}
}
</script>
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Jun 28.2008 — var re = new RegExp(countWord,"g[color=red]i[/color]");

The i tells it not to be case sensitive, so remove it.
Copy linkTweet thisAlerts:
@marringiauthorJun 28.2008 — Brilliant that it was that simple. Thanks for all the help Declan
×

Success!

Help @marringi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...