Ver Mensaje Individual
  #8 (permalink)  
Antiguo 25/09/2008, 10:53
cm_vargas
 
Fecha de Ingreso: julio-2008
Mensajes: 28
Antigüedad: 15 años, 9 meses
Puntos: 1
Respuesta: Cómo llamar función javascript desde php

creo que puedes hacer lo siguiente:
En el caso de no tener las direcciones de las imagenes en una base de datos y de estas ser estaticas:
Código HTML:
<html>
<head>
    <title>Sistema de Noticias</title>
    <script>
    function cambiar(){
    	document.getElementById('divXCambiar').innerHTML = "ADIOS";
    }
    </script>
</head>
<body>
<?php include('db-cnx.php'); ?>

<?php
$idurl=$HTTP_GET_VARS["id"];// Obtienes la id de la categoria seleccionada la cual enviaste por url

if (!empty($idurl)){// si existe un valor en la variable idurl hace lo siguiente

//las constantes de este case las cambias segun los id's de tus categorias
switch($idurl){
case = 1:
echo '<div id = "divXCambiar" style="float: none; width: auto; height: 150px; background: url(./images/new_image1.gif) no-repeat; clear: both;"></div>'
break;

case = 2:
echo '<div id = "divXCambiar" style="float: none; width: auto; height: 150px; background: url(./images/new_image2.gif) no-repeat; clear: both;"></div>'
break;

case = 3:
echo '<div id = "divXCambiar" style="float: none; width: auto; height: 150px; background: url(./images/new_image3.gif) no-repeat; clear: both;"></div>'
break;

default: // esta opcion se activa si pasa un numero que no este en el rango de las categorias
echo '<div id = "divXCambiar" style="float: none; width: auto; height: 150px; background: url(./images/new_image0.gif) no-repeat; clear: both;"></div>'
break;
}
}else{ // si NO existe un valor en la variable idurl hace lo siguiente
echo '<div id = "divXCambiar" style="float: none; width: auto; height: 150px; background: url(./images/new_image.gif) no-repeat; clear: both;"></div>'
}
?>
<h1>Sistema de Noticias</h1>
<div style="float:left; width: 25%;">
    <?php include('list-categoria.php'); ?>
</div>
<div style="float:right; width: 75%;">
    <?php include('list-noticia.php'); ?>
</div>


locura
<br>
<br><br><ul><li><a href='?categoria=CRUZ&amp;id=5'>cruz</a></li></ul>
<input onclick="cCambio()" type="submit" name="Submit" value="Buscar" />
</body>
</html> 
Te doy la respuestas con php porque es mas sencillo pero en javascript si se puede. La otra posible opcion es que en la base de datos donde tienes las categorias agregues otro campo que contenga la direccion de la imagen correspondiente. lo llamas con un select desde php y colocas la variable de la direccion de la imagen mas o menos asi:

Código PHP:
echo '<div id = "divXCambiar" style="float: none; width: auto; height: 150px; background: url(.'.$varDireccionImagen.') no-repeat; clear: both;"></div>'