/    Sign up×
Community /Pin to ProfileBookmark

for loop not working in firefox

I have this code to produce a dynamically shrinking table according to what was typed in a textbox. On IE it works fine but on firefox the For loop doesn’t complete no matter what is in it, it goes through it once then exits. the values of trs.length are always close to 30. any ideas?? “idsl” is the id of the textbox and floopy is the id of the table.

function shrink(idsl)
{
var menuCur = document.getElementById(“floopy”);
var trs = menuCur.getElementsByTagName(“tr”);
var tr;
var td;
var myceltext;
var currenttext;
var item = document.getElementById(idsl);

for (i = 1; i < trs.length; i++)
{
tr = trs[i];
td = tr.getElementsByTagName(“td”).item(2);

myceltext=td.childNodes.item(0);

currenttext=myceltext.data;

if(currenttext.toUpperCase().indexOf(item.value.toUpperCase())==0)
{
tr.style.visibility = “visible”;
tr.style.display =”block”;
}
else
{
tr.style.visibility = “hidden”;
tr.style.display = “none”;
}

}
}

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@PittimannFeb 09.2005 — Hi![i]Originally posted by jacob358 [/i]

[B]var trs = menuCur.getElementsByTagName("tr");[/B][/QUOTE]
That doesn't seem to be a correct reference. What is 'menuCur'? Not looking deeper into the code - why don't you use DOM references concerning that element like you do for others?

Cheers - Pit
Copy linkTweet thisAlerts:
@jacob358authorFeb 09.2005 — menuCur is a table object didn't use DOM because there are multiple tables on this page and its easier to identify the object by its id. The code finds the number of rows in the table but when when there is only an alert("Hi"); in the for loop (and the number of rows it finds is 30) it only pops up one alert box.
Copy linkTweet thisAlerts:
@PittimannFeb 09.2005 — Hi!

What I meant is: why do you not use the correct reference:

var trs = document.getElementById('menuCur').getElementsByTagName("tr");

Trying to access objects by just putting their id or name somewhere might work in IE but not in true DOM browsers.

Cheers - Pit
Copy linkTweet thisAlerts:
@jacob358authorFeb 09.2005 — I am not sure to what you are refering I am currently doing what you suggest

"var trs = document.getElementById('menuCur').getElementsByTagName("tr");"

I am just storing "document.getElementById("floopy")" in a variable (mnuCur) untill I get its rows using

"var trs = menuCur.getElementsByTagName("tr");"

the html for the table looks something like this"

<table id="floopy">

<tr>

<td width="20%"></td>

<td width="44%"></td>

<td width="36%"></td>

</tr>

<tr>

<td>aaa</td>

<td>1</td>

<td>11</td>

</tr>

<tr>

<td>aab</td>

<td>2</td>

<td>12</td>

</tr>

</table>
Copy linkTweet thisAlerts:
@PittimannFeb 09.2005 — Sorry about the confusion! :o

I absolutely overread this line:

'var menuCur = document.getElementById("floopy");' :rolleyes:

in your first post (don't ask me why, please :p).

I'll get back to your thread tomorrow and see, if your problem has been solved (almost midnight and my bed is calling me).

Good luck - Pit
Copy linkTweet thisAlerts:
@jacob358authorFeb 10.2005 — very sorry I sort of figured this out. I didn't include some information on the textbox. This was very wierd calling the EOT function cause the for loop to die, I have no idea why??!?!? turns out I don't neeed the EOT function now anyways so I removed it and now it all works. sometimes javascript is pretty FUBAR guess thats what you get when you try to make a cross browser language.

I had this function to move the cursor to the end of the text in the textfield:

function EOT(txt)

{

var range = txt.createTextRange();

range.move("textedit");
range.select();

}

then I had

<table id = "bigtable">

<tr>

<td>Name:</td>

<td>

<table id="navBar">

<td valign="top" id="item1" >

<input type="text" name="name" value="" onkeyup="shrink('namey');" onfocus="EOT(this);" id="namey"/>
</td>
</table>
</td>

</tr>

</table>
Copy linkTweet thisAlerts:
@PittimannFeb 10.2005 — Hi!

createTextRange() is IE only and will kill the further execution of the script in other browsers.

Cheers - Pit
Copy linkTweet thisAlerts:
@jacob358authorFeb 10.2005 — thanks a bunch for all your help I am still new at javascript stuff. I am used to more consistant languages.
Copy linkTweet thisAlerts:
@PittimannFeb 10.2005 — Well, I guess that yesterday I was the opposite of being a help. I should have gone to bed instead of posting to your thread. :rolleyes:

You could still use the function EOT if you make sure that it will only run, if the user's browser is IE.

Good luck! Pit
×

Success!

Help @jacob358 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.14,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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