2011-09-02 02:57 @164 |
|
|
gonzalos
Perlero Nuevo
|
Registrado: 2009-11-27 05:47 @283 Mensajes: 37
|
|
|
Re: CGI con DIV oculto
|
Buenos días para que se vea más claro aquí dejo el código completo del script, con las modificaciones que se han ido haciendo a lo largo del hilo. Using perl Syntax Highlighting #!c:/xampp/perl/bin/perl.exe
use strict;
use warnings;
use CGI qw/:standard/;
use DBI;
my $denominacion;
my $id;
my $explicacion;
my $grupo;
my $dbh=DBI->connect("DBI:mysql:mysql;host=localhost",'user','pass')
or die "Cannot connect to database:$DBI::errstr";
my $sth=$dbh->prepare("SELECT denominacion,grupo,explicacion FROM lineas ORDER BY grupo");
$sth->execute() or die "Cannot execute sth:$DBI::errstr";
my $codigo_js = <<EOJ;
function muestra_oculta(id) {
if (document.getElementById){ // se obtiene el id
var el = document.getElementById(id); // se define la variable "el" igual a nuestro div
// damos un atributo display:none que oculta el div
el.style.display = (el.style.display == 'none') ? 'block' : 'none';
}
}
window.onload = function() {
// hace que se cargue la función
// lo que predetermina que div estará oculto hasta llamar a la función nuevamente
// "contenido_a_mostrar" es el nombre que le dimos al DIV
muestra_oculta('id');
}
EOJ
;
print header;
print start_html(
-title => 'RECETAS DE COCINA',
-script => $codigo_js,
);
while(($id, $denominacion,$grupo,$explicacion)=$sth->fetchrow_array()){
if ($explicacion eq "") {
$explicacion="<b>sin datos</b>";
}
print
table(
Tr({ -align => 'center', -valign => 'top' }, [
td([
a({ -href => "#", -Onclick => "muestra_oculta('$id')" }, $denominacion),
$grupo,
]),
]),
);
print
div({ id => $id, -style => 'display:none' },
table(
Tr({ -align => 'center', -valign => 'top' }, [
td([
$explicacion,
]),
]),
),
),
};
print end_html;
$dbh->disconnect();
Un saludo Gonzalo
|
2011-09-02 06:31 @313 |
|
|
 |
explorer
Administrador
|
Registrado: 2005-07-24 18:12 @800 Ubicación: Valladolid, España Mensajes: 10216
|
|
|
Re: CGI con DIV oculto
|
Esta es mi versión (no probada): Using perl Syntax Highlighting #!c:/xampp/perl/bin/perl.exe
use strict;
use warnings;
use CGI qw<:standard>;
use DBI;
my $dbh = DBI->connect("DBI:mysql:mysql;host=localhost",'user','pass')
or die "Cannot connect to database:$DBI::errstr";
my $sth = $dbh->prepare("SELECT denominacion,grupo,explicacion FROM lineas ORDER BY grupo");
$sth->execute()
or die "Cannot execute sth:$DBI::errstr";
my $codigo_js = <<EOJ;
function muestra_oculta(id) {
if (document.getElementById){ // se obtiene el id
var el = document.getElementById(id); // se define la variable "el" igual a nuestro div
// damos un atributo display:none que oculta el div
el.style.display = (el.style.display == 'none') ? 'block' : 'none';
}
}
EOJ
print
header,
start_html(
-title => 'RECETAS DE COCINA',
-script => $codigo_js,
-onLoad => "muestra_oculta('id')",
)
;
while(my($id, $denominacion, $grupo, $explicacion) = $sth->fetchrow_array()) {
$explicacion = b('sin datos') if not $explicacion;
print
table(
Tr({ -align => 'center', -valign => 'top' }, [
td([
a({ -href => "#", -Onclick => "muestra_oculta('$id')" }, $denominacion),
$grupo,
]),
]),
),
div({ id => $id, -style => 'display:none' },
table(
Tr({ -align => 'center', -valign => 'top' }, [
td([
$explicacion,
]),
]),
),
)
;
}
print
end_html
;
$dbh->disconnect();
_________________ JF^D Perl programming
|
| Reglas del Foro |
No puedes abrir nuevos temas en este Foro No puedes responder a temas en este Foro No puedes editar tus mensajes en este Foro No puedes borrar tus mensajes en este Foro No puedes enviar adjuntos en este Foro
|
|
Socializa |
 |
|