Markus: Javascriptzähler bereitet Probleme

Beitrag lesen

So hab ein kleines Prob. Hab ein Javascript geschrieben, was den Betrag eines Inputfeldes nach oben oder unten zählen soll, in 1er, 10er, 100er und 1000er Schritten. Maxwert=9999, Minwert=1, Startwert=1. Wenn ich den Maxwert 9999 ändere in z.B. 8888, dann geht beim ersten Klick auf einen up oder down link der Betrag auf 8888 und dann kann man erst hoch oder runter zählen. Bei 9999 ist das nicht der Fall, da geht es von 1 aus ganz normal nach oben. Aber warum nur bei 9999?

Ich weiß, dass es etwas kompliziert geschrieben ist, aber prinzipiell müsste es ja funktionieren, oder?

<html>
<head>
<title></title>
<LINK HREF="style.css" rel="stylesheet" type="text/css">
<script language="javascript">
function thousandup()
{
 for (var i = 1; i <=1000; i++)
 {
  if(document.email_form.email_amount.value>="9999")
  {
   document.email_form.email_amount.value="9999";
  }
  else
  {
   document.email_form.email_amount.value++
  }
 }

}
function thousanddown()
{
 for (var i = 1; i <=1000; i++)
 {
  if(document.email_form.email_amount.value<="1")
  {
   document.email_form.email_amount.value="1";
  }
  else
  {
   document.email_form.email_amount.value--
  }
 }
}
function hundredup()
{
 for (var i = 1; i <=100; i++)
 {
  if(document.email_form.email_amount.value>="9999")
  {
   document.email_form.email_amount.value="9999";
  }
  else
  {
   document.email_form.email_amount.value++
  }
}

}
function hundreddown()
{
 for (var i = 1; i <=100; i++)
 {
  if(document.email_form.email_amount.value<="1")
  {
   document.email_form.email_amount.value="1";
  }
  else
  {
   document.email_form.email_amount.value--
  }
 }
}
function tenup()
{
 for (var i = 1; i <=10; i++)
 {
  if(document.email_form.email_amount.value>="9999")
  {
   document.email_form.email_amount.value="9999";
  }
  else
  {
   document.email_form.email_amount.value++
  }
}

}
function tendown()
{
 for (var i = 1; i <=10; i++)
 {
  if(document.email_form.email_amount.value<="1")
  {
   document.email_form.email_amount.value="1";
  }
  else
  {
   document.email_form.email_amount.value--
  }
 }
}
function oneup()
{
 for (var i = 1; i <=1; i++)
 {
  if(document.email_form.email_amount.value>="9999")
  {
   document.email_form.email_amount.value="9999";
  }
  else
  {
   document.email_form.email_amount.value++
  }
}

}
function onedown()
{
 for (var i = 1; i <=1; i++)
 {
  if(document.email_form.email_amount.value<="1")
  {
   document.email_form.email_amount.value="1";
  }
  else
  {
   document.email_form.email_amount.value--
  }
 }
}

</script>

</head>
<body>

<form action= enctype="multipart/form-data" method="post" name="email_form">
 <table width="400" style="border:1px solid #000000;position:" align="center">
    <tr>
      <td width="121" rowspan="2" class="mailertext">Anzahl *:</td>
      <td width="2" rowspan="2"><input type="text" name="email_amount" maxlength="4"

size="3" value="1" readonly></td>
      <td width="2" rowspan="2" class="mailertext">1</td>
      <td width="6" valign="bottom"><a href="javascript:oneup()"><img src="value_plus.gif"

alt="+1" width="11" height="7" border="0"></a></td>
      <td width="6" rowspan="2" class="mailertext">10</td>
      <td width="6" valign="bottom"><a href="javascript:tenup()"><img src="value_plus.gif"

alt="+10" width="11" height="7" border="0"></a></td>
      <td width="6" rowspan="2" class="mailertext">100</td>
      <td width="6" valign="bottom"><a href="javascript:hundredup()"><img

src="value_plus.gif" alt="+100" width="11" height="7" border="0"></a></td>
      <td width="6" rowspan="2" class="mailertext">1000</td>
      <td width="6" valign="bottom"><a href="javascript:thousandup()"><img

src="value_plus.gif" alt="+1000" width="11" height="7" border="0"></a></td>
    </tr>
    <tr>
      <td valign="top"><a href="javascript:onedown()"><img src="value_minus.gif" alt="-1"

width="11" height="7" border="0"></a></td>
      <td width="6" valign="top"><a href="javascript:tendown()"><img src="value_minus.gif"

alt="-10" width="11" height="7" border="0"></a></td>
      <td width="6" valign="top"><a href="javascript:hundreddown()"><img

src="value_minus.gif" alt="-100" width="11" height="7" border="0"></a></td>
      <td width="6" valign="top"><a href="javascript:thousanddown()"><img

src="value_minus.gif" alt="-1000" width="11" height="7" border="0"></a></td>
    </tr>

</table>
</form>

</body>
</html>