Click to See Complete Forum and Search --> : Works in IE - doesnt work in Netscape???


Otsu
03-13-2005, 07:03 PM
I have some code that works fine in Internet Explorer but not in Netscape.

WHAT THE CODE DOES:
The code is part of a levelling up system for a roleplay game I am creating, character's information is stored in a MySQL database and retrieved into readonly textboxes with some javascript formula to add or subtract a number of points from a total amount given, by clicking '+' and '-' buttons next to the textbox. Then a Submit button runs some php to work out whether people are trying to pull a fast one and cheat the system. The php works fine and this is not the place for that. It is the javascript itself that seems to be creating a 'frm1 is not defined' error when attempting to manipulate the value of the textbox using the buttons. Here is the code:

<script><!--
function ChangeStat(txtBox, Dir){
if(Dir == 1){
if(frm1.txtSum.value != 0){
txtBox.value++;
frm1.txtSum.value--
}else{
alert("please remove points from something first.");
}
}else{
txtBox.value--
frm1.txtSum.value++
}
};

-->
</script>

and the working parts:

<form action="levelup.php" method="post" name="frm1">
<h4 class="style1">Levelling Up Section </h4>
<p align="justify" class="style1">You have
<input type=text readonly name="txtSum" class="style8" id="txtSum" value="<?php echo $Point; ?>"
size="3" maxlength="10" />
points to add to your stats, simply click the up/down arrows next to the stat until the total
no. left has been reduced to 0. When you are happy with your selection, click on
'SUBMIT LEVELLING UP STATS' to submit your information.
If successful, your stats will be updated as soon as possible. </p>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="2">
<tr class="style8">
<td class="style1"><div align="right" class="style8">Intelligence : </div></td>
<td bgcolor="#D4D0C8" class="style2"><span class="style7">
<input type=text readonly name="statintel" class="style8" id="Intel2"
value="<?php echo $Intel; ?>" size="3" maxlength="3" />
<?php if ($Intel == 'NA') {
echo '';
}
else {
echo '<input name=btnStat1Up type=button class="style8" onclick="ChangeStat(frm1.statintel, 1)" value="+" />';
echo '<input name=btnStat1Down type=button class="style8" onclick="ChangeStat(frm1.statintel, -1)" value="-" />';
}
?>

Just ignore the dodgy style stuff, havent cleaned it yet!

The part that seems to be causing a problem is this :

if(frm1.txtSum.value != 0)

Is there some universal simplicity to get this to work in both IE and Netscape or am I going to have to have two different sets of the system with a browser checker?? (I hope not - eek)

Any help would be useful.

Jona
03-13-2005, 07:13 PM
Unless you're working with a quirky engine, like IE's, you're going to have this problem because you never defined a variable with that name. The form's name is not automatically a variable with properties. Instead, you must refer to the object as a property of the object that contains it, in this case the document object. Your code should look like this:


if(document.frm1.txtSum.value != 0){

Otsu
03-13-2005, 07:20 PM
I am guessing you are not a great fan of IE lol

I was going to ask whether I need to add 'document.' before all instances of 'frm1.txtSum.value' etc but I will find out for myself as I am going to test it now - cheers for your help.

Jona
03-13-2005, 07:25 PM
from The Book of Mozilla, 7:15
And so at last the beast fell and the unbelievers rejoiced. But all was not lost, for from the ash rose a great bird. The bird gazed down upon the unbelievers and cast fire and thunder upon them. For the beast had been reborn with its strength renewed, and the followers of Mammon cowered in horror.

JPnyc
03-13-2005, 07:28 PM
Jona got it. You must use the entire object reference.

Otsu
03-13-2005, 07:40 PM
Roger that - works fine now in both IE and Netscape - cheers ppl I will endeavour to learn from this experience lest I get smote down by the wrath of the MAMMON!

BTW - You got an e-book of that somewhere? lol

Jona
03-13-2005, 07:45 PM
An e-book? I wish! If you've got Firefox, type "about:firefox" in the address bar and hit enter. It's an excerpt from the unwritten Book of Mozilla. I'd love to see a whole Mozilla Bible for those of us who follow the Mozillian Religion and praise the Great Phoenix (in a more or less frivolous way). ;)

Edit: By the way, Mammon is IE and its followers are Microsoft employees and people who write code that only works in IE. That's what it is as I interpret this excerpt from the Mozillian Bible, anyway.

Otsu
03-13-2005, 07:54 PM
The "beast" falling refers to Netscape being closed down by its now parent company AOL (though since this verse was written, AOL has resumed releasing Netscape browsers). The "great bird" that rises from the ash is the Mozilla Foundation, which was established to continue Mozilla development, but it can also refer to the project name: "Phoenix" - the bird reborn of fire - given to a project of a trimmed down Mozilla Browser. The bird casting down "fire" refers to the Mozilla Firebird project (continuation of Phoenix, renamed due to possible confusion, later renamed to Mozilla Firefox) and the "thunder" to Mozilla Thunderbird. Both products became the main focus of Mozilla development a few months before the death of Netscape. The fact that the beast has been "reborn" indicates that the spirit of Netscape will live on through the Foundation (which is made up entirely of ex-Netscape employees) and its strength has been "renewed" as the Foundation is less reliant on AOL (who largely neglected Netscape). This time the numbers 7:15 refer to July 15 2003, the day that the Mozilla Foundation was established.

http://www.answers.com/topic/the-book-of-mozilla

Jona
03-13-2005, 07:58 PM
You know, I'm surprised I never checked Answers.com for that information. I use Answers for everything else! Thanks, though. ;)