selectedIndex in Firefox
Simon
- javascript
Hallo,
ich habe ein Problem mit Javascript und Firefox. Ich habe ein Formular, das aus zwei mal drei Auswahlfeldern besteht, mit denen man ein Ankunftsdatum und ein Abreisedatum festlegen kann, also Tag-Monat-Jahr Ankunft und Tag-Monat-Jahr Abreise.
Die drei Auswahlfelder für das Anreisedatum sollen beim Laden der Seite automatisch auf das aktuelle Datum eingestellt sein, während die Auswahlfelder für das Abreisedatum automatisch auf das Datum von heute in einer Woche eingestellt sein sollen.
Dazu verwende ich den unten angefügten Javascript-Code. Das Ganze funktioniert mit Internet Explorer problemlos, aber leider nicht mit Firefox 2.0.
Mit Firefox wird das Ankunftsdatum korrekt auf heute gesetzt, aber beim Abreisedatum werden die entsprechenden Werte in den Auswahlfeldern nicht mehr gesetzt. Ich kann mir das nicht erklären. Kann mir hier bitte jemand weiterhelfen?
Vielen Dank im Voraus für Eure Hilfe!!
Grüsse,
Simon
---------------------------------------------
<html>
<body>
<form name="Formular" action="mail.php" method="post">
<table border="0" width="100%" height="123">
<p align="center"> Zeitraum </p>
<p align="center"> vom
<select size="1" name="von_tag">
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option>
</select>
<select size="1" name="von_monat">
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option>
</select>
<select size="1" name="von_jahr">
<option>2006</option><option>2007</option><option>2008</option>
</select>
bis zum
<select size="1" name="bis_tag">
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option>
</select>
<select size="1" name="bis_monat">
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option>
</select>
<select size="1" name="bis_jahr">
<option>2006</option><option>2007</option><option>2008</option>
</select>
</p>
</form>
<script language="JavaScript">
<!--
heute = new Date();
in1woche = new Date();
document.Formular.von_jahr.selectedIndex = 0;
document.Formular.von_monat.selectedIndex = heute.getMonth();
document.Formular.von_tag.selectedIndex = heute.getDate()-1;
in1woche.setTime(heute.getTime()+604800000);
document.Formular.bis_jahr.selectedIndex = in1woche.getYear()-2006;
document.Formular.bis_monat.selectedIndex = in1woche.getMonth();
document.Formular.bis_tag.selectedIndex = in1woche.getDate()-1;
//-->
</script>
</body>
</html>
[/CODE]
Hi,
Dazu verwende ich den unten angefügten Javascript-Code. Das Ganze funktioniert mit Internet Explorer problemlos, aber leider nicht mit Firefox 2.0.
Dein Code ist fehlerhaft, dass Jahr wird ab 1970 gerechnet. Verwende in1woche.getFullYear(). Ausserdem solltest Du die Ergebnisse erst prüfen, befor Du sie dem Index zuweist
Gruesse, Joachim
Hi,
Dein Code ist fehlerhaft, dass Jahr wird ab 1970 gerechnet.
getYear() liefert die Zahl der Jahre seit 1900. Du verwechselst das mit der bei Linux (und vielen anderen Systemen) üblichen Epoch.
Cheatah