Foros del Web » Programando para Internet » Javascript »

InnerHTML gran problema

Estas en el tema de InnerHTML gran problema en el foro de Javascript en Foros del Web. Hola amigos, soy novato en java y tengo un problema. hice un conversor de fecha de calendario civil al hebreo, pero necesito que el resultado ...
  #1 (permalink)  
Antiguo 25/10/2009, 22:22
 
Fecha de Ingreso: octubre-2009
Mensajes: 10
Antigüedad: 14 años, 6 meses
Puntos: 0
InnerHTML gran problema

Hola amigos, soy novato en java y tengo un problema.
hice un conversor de fecha de calendario civil al hebreo, pero necesito que el resultado de esa conversion me apareza dentro de un <div> ya que en estos momento solo pude hacer que me apareciera en una ventana emergente. de moento lo tengo asi pero no me funciona


Código:
<script type="text/javascript">
//esto es solo una perte del codigo x es larguisimo

 function G2H(nYearG, nMonthG, nDateG) {
	var nYearH
    var nMonthH
    var nDateH
    var dGreg
	var inputResult = document.getElementById(Result).value

	nYearG  = Number(nYearG)
    nMonthG = Number(nMonthG)
    nDateG  = Number(nDateG)
    dGreg   = new Date(nYearG, nMonthG - 1, nDateG)
	
	
document.getElementById('Result').innerHTML = inputResult;

document.write(FormatDate(dGreg) + " = ")
document.write(FormatDateH(GregToHeb(dGreg)))
document.write("<p>")
  }
  
  
</script>



<form >
  Mes <select name="MonthH">
          <option Value="1">Tishrei
          <option Value="2">Jeshvan
          <option Value="3">Kislev
          <option Value="4">Tevet
          <option Value="5">Shevat
          <option Value="6">Adar I
          <option Value="7">Adar (II)
          <option Value="8">Nisan
          <option Value="9">Iyar
          <option Value="10">Sivan
          <option Value="11">Tamuz
          <option Value="12">Av
          <option Value="13">Elul
        </select>
  Dia <select name="DateH">
          <option Value="1">1
          <option Value="2">2
          <option Value="3">3
          <option Value="4">4
          <option Value="5">5
          <option Value="6">6
          <option Value="7">7
          <option Value="8">8
          <option Value="9">9
          <option Value="10">10
          <option Value="11">11
          <option Value="12">12
          <option Value="13">13
          <option Value="14">14
          <option Value="15">15
          <option Value="16">16
          <option Value="17">17
          <option Value="18">18
          <option Value="19">19
          <option Value="20">20
          <option Value="21">21
          <option Value="22">22
          <option Value="23">23
          <option Value="24">24
          <option Value="25">25
          <option Value="26">26
          <option Value="27">27
          <option Value="28">28
          <option Value="29">29
          <option Value="30">30
        </select>
  Año <input type="text" name="YearH" value="">
  <p>
    <input type="button"
         value="Calcular"
         onclick="H2G(YearH.value, MonthH.value, DateH.value)" />
  <div id="Result"></div>
Gracias enormes x su ayuda
  #2 (permalink)  
Antiguo 26/10/2009, 01:21
Avatar de lucasphp  
Fecha de Ingreso: mayo-2009
Ubicación: Misiones
Mensajes: 170
Antigüedad: 15 años
Puntos: 3
Respuesta: InnerHTML gran problema

¿acá intentás meter el resultado?
Código HTML:
document.getElementById('Result').innerHTML = inputResult;
  #3 (permalink)  
Antiguo 26/10/2009, 01:58
Avatar de ceSharp  
Fecha de Ingreso: octubre-2008
Ubicación: Madrid
Mensajes: 495
Antigüedad: 15 años, 6 meses
Puntos: 66
Respuesta: InnerHTML gran problema

Hola kadhessim,

No he analizado a fondo el código pero ya en una linea he visto esto:
----------------------
var inputResult = document.getElementById(Result).value
----------------------
Aquí intentas 'cazar' el ID Result, pero sin comillas. Es decir, que si Result es una variable ya creada y con un valor asignado vale, pero me temo que no es así. Lo que no sé si esto es un error de escritura tuyo o que realmente lo tienes así; si es lo segundo es posible que un fallo de tu código sea ese.
Trata de revisar todo el código porque pueden andar por ahí los tiros...

salu2
  #4 (permalink)  
Antiguo 26/10/2009, 01:58
Avatar de buzu  
Fecha de Ingreso: octubre-2006
Ubicación: San Francisco, CA
Mensajes: 2.168
Antigüedad: 17 años, 6 meses
Puntos: 122
Respuesta: InnerHTML gran problema

Cita:
¿acá intentás meter el resultado?
No, creo que ahi esta intentando obtener un valor de algun input.

Fijate que te faltan las comillas al rededor de Result y ademas en tu code se ve un elemento div con id Result, los div no tienen value, si quieres obtener el valor del un id usa innerHTML. Otra cosa, dependiendo de cuando hagas la llamada a la funcion, puede ser que tus .write no se ejecuten si ya se cerro el buffer del documento.

EDITO: Choque con ceSharp.
__________________
twitter: @imbuzu
  #5 (permalink)  
Antiguo 26/10/2009, 02:13
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: InnerHTML gran problema

otra cosa es la funcion a invocar cuando se presiona el boton, dice H2G y supongo que deberia ser G2H.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #6 (permalink)  
Antiguo 26/10/2009, 07:56
 
Fecha de Ingreso: octubre-2009
Mensajes: 10
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: InnerHTML gran problema

Hola muchachos, probablemente formulé mal la pregunta o es que realmete no entiendo XD, si embargo acá les dejo todo el documento para que vean como lo tego hecho. e estos mometos el resultado sale en ua vetana emergete, pero no quiero que sea así sino dentro de un <div> debajo de del boton "calcular". de nuevo les agradesco!!!!

Código:
<form >
  <p>
    <select name="MonthG" >
      <option Value="1">en
        <option Value="2">Feb
        <option Value="3">Mar
        <option Value="4">Abr
        <option Value="5">May
        <option Value="6">Jun
        <option Value="7">Jul
        <option Value="8">Ago
        <option Value="9">Sep
        <option Value="10">Oct
        <option Value="11">Nov
        <option Value="12">Dic
      </select><select name="DateG">
        <option Value="1">1
        <option Value="2">2
        <option Value="3">3
        <option Value="4">4
        <option Value="5">5
        <option Value="6">6
        <option Value="7">7
        <option Value="8">8
        <option Value="9">9
        <option Value="10">10
        <option Value="11">11
        <option Value="12">12
        <option Value="13">13
        <option Value="14">14
        <option Value="15">15
        <option Value="16">16
        <option Value="17">17
        <option Value="18">18
        <option Value="19">19
        <option Value="20">20
        <option Value="21">21
        <option Value="22">22
        <option Value="23">23
        <option Value="24">24
        <option Value="25">25
        <option Value="26">26
        <option Value="27">27
        <option Value="28">28
        <option Value="29">29
        <option Value="30">30
        <option Value="31">31
        </select><input type="text" name="YearG" value="Año">  
  <p>  
  <input type="button"
         value="Calcular"
         onclick="G2H(YearG.value, MonthG.value, DateG.value)" />  
</form>

<script type="text/javascript">
  
  function MonSinceFirstMolad(nYearH) {
    var nMonSinceFirstMolad
    
    nYearH --

    nMonSinceFirstMolad = Math.floor(nYearH / 19) * 235
    
    nYearH = nYearH % 19
    
    nMonSinceFirstMolad += 12 * nYearH
   
    if (nYearH >= 17) {
      nMonSinceFirstMolad += 6
    } else if  (nYearH >= 14) {
      nMonSinceFirstMolad += 5
    } else if  (nYearH >= 11) {
      nMonSinceFirstMolad += 4
    } else if  (nYearH >= 8) {
      nMonSinceFirstMolad += 3
    } else if  (nYearH >= 6) {
      nMonSinceFirstMolad += 2
    } else if  (nYearH >= 3) {
      nMonSinceFirstMolad += 1
    }
    return nMonSinceFirstMolad
  }
  
  function IsLeapYear(nYearH) {
     var nYearInCycle

    nYearInCycle = nYearH % 19
    return ( nYearInCycle ==  3 ||
             nYearInCycle ==  6 ||
             nYearInCycle ==  8 ||
             nYearInCycle == 11 ||
             nYearInCycle == 14 ||
             nYearInCycle == 17 ||
             nYearInCycle == 0)
  }

  
  function Tishrei1(nYearH) {
    var nMonthsSinceFirstMolad
    var nChalakim
    var nHours
    var nDays
    var nDayOfWeek
    var dTishrei1
    
    nMonthsSinceFirstMolad = MonSinceFirstMolad(nYearH)
    nChalakim = 793 * nMonthsSinceFirstMolad
    nChalakim += 204
    
    nHours = Math.floor(nChalakim / 1080)
    nChalakim = nChalakim % 1080

    nHours += nMonthsSinceFirstMolad * 12
    nHours += 5

    
    nDays = Math.floor(nHours / 24)
    nHours = nHours % 24

    nDays += 29 * nMonthsSinceFirstMolad
    nDays += 2

    
    nDayOfWeek = nDays % 7

    if (!IsLeapYear(nYearH) &&
        nDayOfWeek == 3 &&
        (nHours * 1080) + nChalakim >= (9 * 1080) + 204) {

      nDayOfWeek = 5
      nDays += 2
    }
    else if ( IsLeapYear(nYearH - 1) &&
              nDayOfWeek == 2 &&
              (nHours * 1080) + nChalakim >= (15 * 1080) + 589 ) {

      nDayOfWeek = 3
      nDays += 1
    }
    else {

      if (nHours >= 18) {
        nDayOfWeek += 1
        nDayOfWeek = nDayOfWeek % 7
        nDays += 1
      }

      if (nDayOfWeek == 1 ||
          nDayOfWeek == 4 ||
          nDayOfWeek == 6) {
        nDayOfWeek += 1
        nDayOfWeek = nDayOfWeek % 7
        nDays += 1
      }
    }

    nDays -= 2067025
    dTishrei1 = new Date(1900, 0, 1)
    dTishrei1.setDate(dTishrei1.getDate() + nDays)

    return dTishrei1
   }



  function LengthOfYear(nYearH) {
    var dThisTishrei1
    var dNextTishrei1
    var diff

    dThisTishrei1 = Tishrei1(nYearH)
    dNextTishrei1 = Tishrei1(nYearH + 1)

    diff = (dNextTishrei1 - dThisTishrei1) / ( 1000 * 60 * 60 * 24)
    return Math.round(diff)
  }


  function GregToHeb(dGreg) {
    var nYearH
    var nMonthH
    var nDateH
    var nOneMolad
    var nAvrgYear
    var nDays
    var dTishrei1
    var nLengthOfYear
    var bLeap
    var bHaser
    var bShalem
    var nMonthLen
    var bWhile
    var d1900 = new Date(1900, 0, 1)


    nOneMolad = 29 + (12 / 24) + (793 / (1080 * 24))

    nAvrgYear = nOneMolad * (235 / 19)

    nDays = Math.round((dGreg - d1900) / (24 * 60 * 60 * 1000))
    nDays += 2067025 
    nYearH = Math.floor(nDays / nAvrgYear) + 1

    dTishrei1 = Tishrei1(nYearH)

    if (SameDate(dTishrei1, dGreg)) {

      nMonthH = 1
      nDateH = 1
    }
    else  {

      if (dTishrei1 < dGreg) {

        while (Tishrei1(nYearH + 1) <= dGreg) {
          nYearH += 1
        }
      }
      else {

        nYearH -= 1
        while (Tishrei1(nYearH) > dGreg) {
          nYearH -= 1
        }
      }


      nDays = (dGreg - Tishrei1(nYearH)) / (24 * 60 * 60 * 1000)
      nDays = Math.round(nDays)

      nLengthOfYear = LengthOfYear(nYearH)
      bHaser = nLengthOfYear == 353 || nLengthOfYear == 383
      bShalem = nLengthOfYear == 355 || nLengthOfYear == 385
      bLeap = IsLeapYear(nYearH)


      nMonthH = 1
      do {

        switch (nMonthH) {
          case 1:
          case 5:
          case 6:
          case 8:
          case 10:
          case 12:
            nMonthLen = 30
            break
          case 4:
          case 7:
          case 9:
          case 11:
          case 13:
            nMonthLen = 29
            break
          case 6: 
            nMonthLen = 30
            break
          case 2: 
            nMonthLen = (bShalem ? 30 : 29)
            break
          case 3: 
            nMonthLen = (bHaser ? 29: 30)
            break
        }

        if (nDays >= nMonthLen) {
          bWhile = true
          if (bLeap || nMonthH != 5) {
            nMonthH ++
          }
          else {

            nMonthH += 2
          }
          nDays -= nMonthLen
        }
        else {
          bWhile = false
        }
      } while (bWhile)

      nDateH = nDays + 1
    }
    return nMonthH + "/" + nDateH + "/" + nYearH
  }

  function SameDate(d1, d2) {
    return (d1.getFullYear() == d2.getFullYear() && 
            d1.getMonth() == d2.getMonth() && 
            d1.getDate() == d2.getDate())
             
  } 



  function FormatDateH(cDate) {
    var aDate = new Array()
    var cFormatDate

    aDate = cDate.split("/")
    switch (Number(aDate[0])) {
      case 1:
        cFormatDate = "Tishrei"
        break
      case 2:
        cFormatDate = "Jeshvan"
        break
      case 3:
        cFormatDate = "Kislev"
        break
      case 4:
        cFormatDate = "Tevet"
        break
      case 5:
        cFormatDate = "Shevat"
        break
      case 6:
        cFormatDate = "Adar I"
        break
      case 7:
        cFormatDate = (IsLeapYear(Number(aDate[2])) ? "Adar II" : "Adar")
        break
      case 8:
        cFormatDate = "Nisan"
        break
      case 9:
        cFormatDate = "Iyar"
        break
      case 10:
        cFormatDate = "Sivan"
        break
      case 11:
        cFormatDate = "Tamuz"
        break
      case 12:
        cFormatDate = "Av"
        break
      case 13:
        cFormatDate = "Elul"
        break
    }
    cFormatDate += " " + aDate[1] + ", " + aDate[2]
    return cFormatDate
  }

  function FormatDate(dDate) {
    var sDate
    switch (dDate.getDay()) {
      case 0:
        sDate = "Domingo "
        break
      case 1:
        sDate = "Lunes "
        break
      case 2:
        sDate = "Martes "
        break
      case 3:
        sDate = "Miércoles "
        break
      case 4:
        sDate = "Jueves "
        break
      case 5:
        sDate = "Viernes "
        break
      case 6:
        sDate = "Sábado "
        break
    }
    sDate += (dDate.getMonth() + 1) + "/"
    sDate += dDate.getDate() + "/"
    sDate += dDate.getFullYear()
    return sDate
  }


  function G2H(nYearG, nMonthG, nDateG) {
	var nYearH
    var nMonthH
    var nDateH
    var dGreg

    nYearG  = Number(nYearG)
    nMonthG = Number(nMonthG)
    nDateG  = Number(nDateG)
    dGreg   = new Date(nYearG, nMonthG - 1, nDateG)
	
	var myWinG2H = window.open("", "","width=450,height=200");

	myWinG2H.document.write(FormatDate(dGreg) + " = ")
	myWinG2H.document.write(FormatDateH(GregToHeb(dGreg)))
	myWinG2H.document.write("<p>")
  }
  
  
</script>
  #7 (permalink)  
Antiguo 26/10/2009, 09:16
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: InnerHTML gran problema

es cuestiond cambiar estas lineas de la funcion G2H,
Código:
	var myWinG2H = window.open("", "","width=450,height=200");

	myWinG2H.document.write(FormatDate(dGreg) + " = ")
	myWinG2H.document.write(FormatDateH(GregToHeb(dGreg)))
	myWinG2H.document.write("<p>")
cambiala por lo necesario para escribir en un elemento
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #8 (permalink)  
Antiguo 26/10/2009, 21:52
Avatar de buzu  
Fecha de Ingreso: octubre-2006
Ubicación: San Francisco, CA
Mensajes: 2.168
Antigüedad: 17 años, 6 meses
Puntos: 122
Respuesta: InnerHTML gran problema

Como decia, tiene que ver con el bufer. Una vez se ha cerrado no puedes abrirlo nuevamente. Lo mejor es usar ya sea DOM o fuerza bruta (lease innerHTML)
__________________
twitter: @imbuzu
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:32.