...

View Full Version : works in Firefox and not IE



boeing747fp
07-31-2006, 04:35 PM
i have a javascript that is initiated when someone hits the "delete" icon for a specific row on a page and it works PERFECTLY in Firefox, but in IE, the rows below the row that is deleted do not change their "num" values nor their names.


function removeRow(num,type){
if(type == "topsr"){
var typef = "Top Seniors";
}else if(type == "topsleep"){
var typef = "Top Sleepers";
}else if(type == "topfuture"){
var typef = "Top Future";
}
var confirmit = confirm("Are you sure you want to remove `"+typef+"` #"+num+"?");
if(confirmit){
//begin removal process
document.getElementById(type+"_"+num+"_value").value='';
document.getElementById(type+"_"+num).style.display='none';
var currentcount = document.getElementById('num_'+type).value;
for(var count=parseInt(num)+1; count <= currentcount; count++){
var newnum = count-1;
document.getElementById(type+'_'+count+'_num').id=type+'_'+newnum+'_num';
document.getElementById(type+'_'+newnum+'_num').name=type+'_'+newnum+'_num';
document.getElementById(type+'_'+count).id=type+'_'+newnum;
document.getElementById(type+'_'+newnum+'_num').value=parseInt(count)-1;
document.getElementById(type+'_'+count+'_value').id=type+'_'+newnum+'_value';
document.getElementById(type+'_'+newnum+'_value').name=type+'_'+newnum+'_value';
}
document.getElementById('num_'+type).value=parseInt(currentcount)-1;
}
}

boeing747fp
08-01-2006, 06:55 AM
anyone know why Firefox does what my script (above) tells it but IE only works up to the following line:

document.getElementById(type+"_"+num).style.display='none';
//stops doing what it's told after this


???

Kor
08-01-2006, 08:59 AM
var count=parseInt(num)+1

this could be the problem. If num is something like '08', for instance, parseInt() - which meaning is in fact to parse a number from a base in decimal - will take it as an octal

try:
alert(parseInt('08'))
to see what I mean

You must set the base

parseInt(num,10)
or better use Number() method instead.

boeing747fp
08-01-2006, 09:37 AM
well i can assure you there are no "0"s in it because the php loop uses for($i=1;$i<=$max;$i++){} and if that was the case it wouldnt work in firefox.

Kor
08-01-2006, 09:45 AM
Can we see the whole code?

boeing747fp
08-01-2006, 09:51 AM
well there's the code above that is in the <head> section
and this is one of the many nearly identical clauses in PHP (the only difference in the other ones is that they are not the same "section" (topsr, topsleep, etc)

while($rf = mysql_fetch_array($dg)){
$dfg = mysql_query("SELECT `full_name` FROM `playerprofiles` WHERE `id` = '$rf[player_id]'") or die(mysql_error());
$rbr = mysql_fetch_array($dfg);
$player = stripslashes($rbr[full_name]);
echo "<span id=\"topsleep_$rf[num]\" class=\"topsleep_row\">#<input class=\"input\" type='text' size='3' maxlength=\"2\" name=\"topsleep_$rf[num]_num\" id=\"topsleep_$rf[num]_num\" value='$rf[num]'>: <input class=\"input\" tabindex=\"1\" type=\"text\" name=\"topsleep_$rf[num]_value\" value=\"$player\" id=\"topsleep_$rf[num]_value\" onChange=\"document.getElementById('current_number_focus').value='$rf[num]';document.getElementById('current_type_focus').value='topsleep';return checkPlayerName(this.value);\"><a href=\"javascript:moveUp('$rf[num]','topsleep');\"><img src=\"../valueboard/up.gif\" width=\"14\" height=\"15\" border=\"0\"></a><a href=\"javascript:moveDown('$rf[num]','topsleep');\"><img src=\"../valueboard/down.gif\" width=\"14\" height=\"15\" border=\"0\"></a><a href=\"javascript:removeRow('$rf[num]','topsleep');\"><img src=\"../v3/error.gif\" width=\"14\" height=\"15\" border=\"0\"></a><br /></span>";
}

boeing747fp
08-01-2006, 09:56 AM
the problem is that the part that is supposed to make all the rows beneath the removed one subtract 1 number from their value, it doesnt want to do it in IE... it removes the row and keeps their current numbers (so if i remove row # 19, the next row stays #20... but in firefox, it does work and #20 becomes #19)

boeing747fp
08-01-2006, 09:51 PM
ooo... just noticed IE gives me this error (and firefox doesnt)

the line is
document.getElementById(type+'_'+count).id=type+'_'+newnum;

and i get "document.getElementById(type+'_'+count) is null or not an object"

Kor
08-01-2006, 11:19 PM
that could mean that either "type" or "count" or both are not defined. Or the object does not exist.

Use alert() method from line to line to check different things. It is a good "debug" way.

On the other hand, IE, specially, is very nervous when using variable named as javascript reserved words, or even the same as the window or document properties. Could be "type?
----
FireFox console is of a good help in cases like that... You might hev forget to close the function, or the brackets... or... FF console is good in case of.

boeing747fp
08-01-2006, 11:23 PM
nope that didnt do it either... the weirdest thing is that it works in firefox. usually it's backwards (works in IE and not firefox) but this situation is baffling.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum