Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/09/2005, 19:58
Avatar de jeanclon
jeanclon
 
Fecha de Ingreso: mayo-2005
Mensajes: 258
Antigüedad: 19 años, 7 meses
Puntos: 2
Pregunta Script de Fecha en Mozilla...

Saludos...

Tengo el siguiente script para colocar la fecha usando tres option select:

Código:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
//set todays date
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape
//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
  var DaysInMonth = 31;
  if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
  if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4)) DaysInMonth = 28;
  if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4)) DaysInMonth = 29;
  return DaysInMonth;
}
//function to change the available days in a months
function ChangeOptionDays(Which)
{
  DaysObject = eval("document.Form1." + Which + "Day");
  MonthObject = eval("document.Form1." + Which + "Month");
  YearObject = eval("document.Form1." + Which + "Year");
  Month = MonthObject[MonthObject.selectedIndex].text;
  Year = YearObject[YearObject.selectedIndex].text;
  DaysForThisSelection = DaysInMonth(Month, Year);
  CurrentDaysInSelection = DaysObject.length;
  if (CurrentDaysInSelection > DaysForThisSelection)
  {
    for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
    {
      DaysObject.options[DaysObject.options.length - 1] = null
    }
  }
  if (DaysForThisSelection > CurrentDaysInSelection)
  {
    for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
    {
      NewOption = new Option(DaysObject.options.length + 1);
      DaysObject.add(NewOption);
    }
  }
    if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}
//function to set options to today
function SetToToday(Which)
{
  DaysObject = eval("document.Form1." + Which + "Day");
  MonthObject = eval("document.Form1." + Which + "Month");
  YearObject = eval("document.Form1." + Which + "Year");
  YearObject[0].selected = true;
  MonthObject[NowMonth].selected = true;
  ChangeOptionDays(Which);
  DaysObject[NowDay-1].selected = true;
}
//function to write option years plus x
function WriteYearOptions(YearsAhead)
{
  line = "";
  for (i=0; i<YearsAhead; i++)
  {
    line += "<OPTION>";
    line += NowYear - i;
  }
  return line;
}
//  End -->
</SCRIPT>

Usando estos select:

Código PHP:
 <FORM NAME="Form1"
    <
SELECT NAME="FirstSelectDay">
      <
option value="01"></option>
      <
option value="02"></option>
      <
option value="03"></option>
      <
option value="04"></option>
      <
option value="05"></option>
      <
option value="06"></option>
      <
option value="07"></option>
      <
option value="08"></option>
      <
option value="09"></option>
      <
option value="10">10 </option>
      <
option value="11">11 </option>
      <
option value="12">12 </option>
      <
option value="13">13 </option>
      <
option value="14">14 </option>
      <
option value="15">15 </option>
      <
option value="16">16 </option>
      <
option value="17">17 </option>
      <
option value="18">18 </option>
      <
option value="19">19 </option>
      <
option value="20">20 </option>
      <
option value="21">21 </option>
      <
option value="22">22 </option>
      <
option value="23">23 </option>
      <
option value="24">24 </option>
      <
option value="25">25 </option>
      <
option value="26">26 </option>
      <
option value="27">27 </option>
      <
option value="28">28 </option>
      <
option value="29">29 </option>
      <
option value="30">30 </option>
      <
option value="31">31 </option
    </
SELECT
    <
SELECT NAME="FirstSelectMonth"
     
ONCHANGE="ChangeOptionDays('FirstSelect')">
      <
option value="01">Jan </option>
      <
option value="02">Feb </option>
      <
option value="03">Mar </option>
      <
option value="04">Apr </option>
      <
option value="05">May </option>
      <
option value="06">Jun </option>
      <
option value="07">Jul </option>
      <
option value="08">Aug </option>
      <
option value="09">Sep </option>
      <
option value="10">Oct </option>
      <
option value="11">Nov </option>
      <
option value="12">Dec </option
    </
SELECT
    <
SELECT NAME="FirstSelectYear"
     
ONCHANGE="ChangeOptionDays('FirstSelect')"> <SCRIPT LANGUAGE="JavaScript">
  
document.write(WriteYearOptions(50));
 
</SCRIPT>
    </SELECT> 
    
    </FORM> 
Esto funciona perfectamente en IE explorer, coloca la cantidad de dias correspondiente a el mes seleccionado, diferenciando ademas años bisiestos. Es muy bueno por que no es posible colocar una fecha erronea.

El problema en Mozilla es el siguiente, empieza bien pero si llego a seleccionar el mes de febrero coloca en el campo dia solo hasta el 28 pero al volver a querer colocar otro mes con mas dias, ya no vuelve a colocar los valores mayores a 28, cosa que si hace en el IE explorer.

Que será lo que esta mal, se podrá cambiar algo para que funcione en Mozilla???, probablemente una instruccion en el script...