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.
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.