Foros del Web » Programando para Internet » Javascript »

Una ayudita para un novato..

Estas en el tema de Una ayudita para un novato.. en el foro de Javascript en Foros del Web. Me podeis hechar una mano para pasar este codigo a javascript???? <Script Language="VBscript"> <!-- Option Explicit DIM menuID,menuObj,cellBk SUB ShowHide(menuID) menuObj = "Link" & menuID ...
  #1 (permalink)  
Antiguo 21/04/2006, 13:08
 
Fecha de Ingreso: octubre-2005
Mensajes: 52
Antigüedad: 18 años, 6 meses
Puntos: 0
Una ayudita para un novato..

Me podeis hechar una mano para pasar este codigo a javascript????

<Script Language="VBscript">
<!--
Option Explicit
DIM menuID,menuObj,cellBk
SUB ShowHide(menuID)
menuObj = "Link" & menuID
cellbk = "Head" & menuID
// CHECK IF OPEN
if document.all.item(menuObj).className = "LINKSON" then 'IF MENU OPEN THEN CLOSE
document.all.item(menuObj).className = "LINKSOFF"
document.all.item(cellBk).style.backgroundColor = "#0080C1" ' SET CELL BACKGROUND COLOUR Azul claro
ELSE
document.all.item(menuObj).className = "LINKSON" ' OPEN MENU
document.all.item(cellBk).style.backgroundColor = "#004080" ' SET CELL BACKGROUND COLOUR Azul mas oscuro
END IF
END SUB
-->
</Script>


Gracias y un saludo
  #2 (permalink)  
Antiguo 21/04/2006, 13:30
 
Fecha de Ingreso: febrero-2006
Mensajes: 56
Antigüedad: 18 años, 2 meses
Puntos: 0
De acuerdo Hola

creo que es mejor especificar que es lo que quieres hacer....conmucho gusto te ayudaremos...

oscar
  #3 (permalink)  
Antiguo 21/04/2006, 13:41
 
Fecha de Ingreso: octubre-2005
Mensajes: 52
Antigüedad: 18 años, 6 meses
Puntos: 0
La verdad es que no me he explicado...

A ver ese codigo pertenece a un bloke de phpnuke, concretamente a un bloque de un menu desplegable, lo podeis ver en ares-infer.es, el caso es que solo funciona en internet explorer y por lo que he podido ver es porque esta programado en vbscipt y creo que la solucion seria pasarlo a javascript pero yo la verdad es que no se ni por donde empezar el codigo completo sera este:

------------

<?
if (eregi("block-DHTML_MENU.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}

$content = <<<_DHTML_
<style>
<!--
a.nav:link { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: none }
a.nav:visited { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: none }
a.nav:active { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: none }
a.nav:hover { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: none; color: #0080C1 }
.HEADING { cursor: hand; font-family: Verdana,Arial,San Serif; font-size: 12px; color: #FFFFFF;
background-color: #0080C1; font-weight: none;
border: 1 solid #000000 }
.LINKSOFF { display: none; font-family: Verdana,Arial,San Serif; font-size: 12px; color: #000080 }
.LINKSON { display: inline; font-family: Verdana,Arial,San Serif; font-size: 12px; color: #000080 }
-->
</style>
</head>
<Script Language="VBscript">

<!--
Option Explicit
DIM menuID,menuObj,cellBk
SUB ShowHide(menuID)
menuObj = "Link" & menuID
cellbk = "Head" & menuID
// CHECK IF OPEN
if document.all.item(menuObj).className = "LINKSON" then 'IF MENU OPEN THEN CLOSE
document.all.item(menuObj).className = "LINKSOFF"
document.all.item(cellBk).style.backgroundColor = "#0080C1" ' SET CELL BACKGROUND COLOUR Azul claro
ELSE
document.all.item(menuObj).className = "LINKSON" ' OPEN MENU
document.all.item(cellBk).style.backgroundColor = "#004080" ' SET CELL BACKGROUND COLOUR Azul mas oscuro
END IF
END SUB
-->
</Script>
<body>
<table>


<!-- Aqui va el titulo del menú 1 -->
<td ID="head1" ALIGN="center" width="113" height="15" CLASS="HEADING" ONCLICK="ShowHide(1)">Ares Infer</td>
</tr>
<tr>
<td ALIGN="left" bgcolor="#FFFFCC">
<!-- Menu 1 -->
<div ID="Link1" CLASS="LINKSOFF">
<a CLASS="nav" href="index.php"><b>Bienvenida</b></a><br>
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=13" ><strong>Ubicación</strong></a><br>
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=14" ><strong>Links de interés</strong></a><br>
<a CLASS="nav" href="contacto.htm" target="_blank"><strong>Contacto</strong></a><br>
<a CLASS="nav" href="bolsa.htm" target="_blank"><strong>Bolsa de Trabajo</strong></a><br>
</div>
</td>
</tr>
<tr>

<!-- Aqui va el titulo del menú 2 -->
<td ID="head2" ALIGN="center" width="113" height="15" CLASS="HEADING" ONCLICK="ShowHide(2)">Cursos</td>
</tr>
<tr>
<td ALIGN="left" bgcolor="#FFFFCC">
<!-- Menu 2 -->
<div ID="Link2" CLASS="LINKSOFF">
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=15" ><strong>Nuestros Cursos</strong></a><br>
</div>
</td>
</tr>
<tr>

<!-- Aqui va el titulo del menú 3 -->
<td ID="head3" ALIGN="center" width="113" height="15" CLASS="HEADING" ONCLICK="ShowHide(3)">Cursos SEF</td>
</tr>
<tr>
<td ALIGN="left" bgcolor="#FFFFCC">
<!-- Menu 3 -->
<div ID="Link3" CLASS="LINKSOFF">
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=9"> <strong>C. Subvencionados por el SEF</strong></a><br>
</div>
</td>
</tr>
<tr>

<!-- Aqui va el titulo del menú 4 -->
<td ID="head4" ALIGN="center" CLASS="HEADING" ONCLICK="ShowHide(4)">Oposiciones</td>
</tr>
<tr>
<td ALIGN="left" bgcolor="#FFFFCC">
<!-- Menu 4 -->
<div ID="Link4" CLASS="LINKSOFF">
<a href="modules.php?name=Content&pa=showpage&pid=1" CLASS="nav"><strong>Estado 2005</strong></a>
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=2"> <strong>Comunidad Autónoma de Murcia 2005</strong></a><br>
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=3"> <strong>Ministerio de Justicia</strong></a><br>
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=4"> <strong>Universidad de Murcia</strong></a><br>
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=5"> <strong>Ayuntamiento de Murcia</strong></a><br>
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=6"> <strong>Ayuntamiento de Cartagena</strong></a><br>
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=7"> <strong>Ayuntamiento de Lorca</strong></a><br>
<a CLASS="nav" href="modules.php?name=Content&pa=showpage&pid=8"> <strong>Fuerzas y Cuerpos de Seguridad del Estado</strong></a><br>
</div>
</td>
</tr>
<tr>



<!-- Aqui va el titulo del menú 5 -->
<td ID="head5" ALIGN="center" CLASS="HEADING" ONCLICK="ShowHide(5)">Administración</td>
</tr>
<tr>
<td ALIGN="left" bgcolor="#FFFFCC">
<!-- Menu 5 -->
<div ID="Link5" CLASS="LINKSOFF">
<a CLASS="nav" href="admin.php"><b>Area Administrativa</b></a><br>
</div>
</td>
</tr>
</table>
_DHTML_;
?>

---------------------

Solo puse el trozo de codigo que pertenecia a vbsript ya que lo demas son estilos y eso si lo domino, no se si sera muy dificil...

Gracias por vuestra ayuda. Un saludo.
  #4 (permalink)  
Antiguo 21/04/2006, 16:02
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 3 meses
Puntos: 146
El trozo de código vbscript solo es este:

<Script Language="VBscript">

Cita:
<!--
Option Explicit
DIM menuID,menuObj,cellBk
SUB ShowHide(menuID)
menuObj = "Link" & menuID
cellbk = "Head" & menuID
// CHECK IF OPEN
if document.all.item(menuObj).className = "LINKSON" then 'IF MENU OPEN THEN CLOSE
document.all.item(menuObj).className = "LINKSOFF"
document.all.item(cellBk).style.backgroundColor = "#0080C1" ' SET CELL BACKGROUND COLOUR Azul claro
ELSE
document.all.item(menuObj).className = "LINKSON" ' OPEN MENU
document.all.item(cellBk).style.backgroundColor = "#004080" ' SET CELL BACKGROUND COLOUR Azul mas oscuro
END IF
END SUB
-->
</Script>
¿lo que pides es que alguien pase por ti ese código a js? o ¿cuál es el problema que tienes?

Saludos
  #5 (permalink)  
Antiguo 22/04/2006, 15:15
 
Fecha de Ingreso: octubre-2005
Mensajes: 52
Antigüedad: 18 años, 6 meses
Puntos: 0
En primer lugar decir q ni mucho menos pretendo que nadie haga esto por mi.

En segundo ya he comprendido el funconamiento mas o menos, de forma que en javascript seria algo asi:

<Script Language="Javascript">

var menuID,menuObj,cellBk --------> asi estan bien declaradas las variables?

--> Ahora el sub lo cambio por function --

function ShowHide(menuID){
menuObj = "Link" & menuID
cellbk="Head" & menuID
//Comprobar si esta abierto

---> y el bucle if

if (document.all.item(menuObj).className = "LINKSON"){
document.all.item(menuObj).className = "LINKSOFF"
document.all.item(cellBk).style.backgroundColor = "#0080C1"
}else{
document.all.item(menuObj).className = "LINKSON"
document.all.item(cellBk).style.backgroundColor = "#004080"
}
}
</script>


Lo que no se es si para acceder a la clase "LINKSON" y "LINKSOFF" se hace en javascript asi tambien "document.all.item(menuObj).className=...

La verdad es que no se si estoy haciendo alguna locura y si asi funcionaria???

Un saludo.
  #6 (permalink)  
Antiguo 22/04/2006, 15:24
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
Hola:

Te recomiendo que cambies document.all.item(x) por document.getElementById(x)... es estenadar y funciona en todos los navegadores modernos...

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #7 (permalink)  
Antiguo 23/04/2006, 01:51
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
También debes cambiar los & por + para hacer las concatenaciones
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 23:51.