Foros del Web » Programando para Internet » Javascript »

2 funciones con un solo botón

Estas en el tema de 2 funciones con un solo botón en el foro de Javascript en Foros del Web. Hola. Necesito una mano. No se me imprimen las imágenes; sólo el "alert" y no sé por qué. Muchas gracias. <html> <head> <script type="text/javascript"> <!-- ...
  #1 (permalink)  
Antiguo 08/12/2011, 12:58
 
Fecha de Ingreso: agosto-2011
Mensajes: 8
Antigüedad: 12 años, 8 meses
Puntos: 0
2 funciones con 1 solo botón

Hola.
Necesito una mano. No se me imprimen las imágenes; sólo el "alert" y no sé por qué.
Muchas gracias.
<html>

<head>
<script type="text/javascript">
<!--
function SetImage(id, filename)
{
var elem=document.getElementById(id);
if(elem)
{
elem.src=filename;
}
}
//-->
</script>
<SCRIPT language=JavaScript>
onload=init;
function init()
{
document.form1.Button1.onclick=pruebaClic;
}
function pruebaClic()
{
alert("¡ El botón ha sido pulsado !");
}
</SCRIPT>
</head>
<body>
<FORM name=form1>
<input type="submit" id="Button1" onclick="SetImage('Shape1','images/alligator.gif');
SetImage('Shape2','images/España.jpg');
return false;" name="pepe" value="Submit" style="position:absolute;left:277px;top:260px;widt h:96px;height:25px;font-family:Arial;font-size:13px;z-index:0">
<div id="wb_Shape1" style="margin:0;padding:0;position:absolute;left:5 45px;top:290px;width:92px;height:55px;text-align:center;z-index:1;">
<img src="images/img0001.gif" id="Shape1" alt="" title="" style="border-width:0;width:92px;height:55px"></div>
<div id="wb_Shape2" style="margin:0;padding:0;position:absolute;left:5 37px;top:224px;width:86px;height:35px;text-align:center;z-index:2;">
<img src="images/img0002.gif" id="Shape2" alt="" title="" style="border-width:0;width:86px;height:35px"></div>
</FORM>
</body>
</html>
  #2 (permalink)  
Antiguo 08/12/2011, 14:43
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: 2 funciones con 1 solo botón

prueba así
Cita:
<!--
function SetImage(id, filename)
{
var elem=document.getElementById(id);
if(elem)
{
elem.src=filename;
}
}

function pruebaClic()
{
alert("¡ El botón ha sido pulsado !");
}

function init()
{
document.form1.Button1.onclick= function() {pruebaClic(); SetImage('Shape1','img1.png'); SetImage('Shape2','img2.png');}
}


window.onload=init;
//-->


<FORM name=form1>
<input type="button" id="Button1" name="pepe" value="Submit" style="position:absolute;left:277px;top:260px;widt h:96px;height:25px;font-family:Arial;font-size:13px;z-index:0">
<div id="wb_Shape1" style="margin:0;padding:0;position:absolute;left:5 45px;top:290px;width:92px;height:55px;text-align:center;z-index:1;">
<img src="img3.png" id="Shape1" alt="" title="" style="border-width:0;width:92px;height:55px;" /></div>
<div id="wb_Shape2" style="margin:0;padding:0;position:absolute;left:5 37px;top:224px;width:86px;height:35px;text-align:center;z-index:2;">
<img src="img3.png" id="Shape2" alt="" title="" style="border-width:0;width:86px;height:35px;" /></div>
</FORM>
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}
  #3 (permalink)  
Antiguo 10/12/2011, 05:04
 
Fecha de Ingreso: agosto-2011
Mensajes: 8
Antigüedad: 12 años, 8 meses
Puntos: 0
2 funciones con un solo botón

Hola, de nuevo.
He estado simplificando mi código, pero sigue sin funcionarme.
¿Me podeis hechar una mano?
Muchas gracias.

<HTML>
<HEAD>
<SCRIPT language=JavaScript>
onload=init;
function init()
function init()
{
document.form1.Button1.onclick= function() {pruebaClic();
escribirBienvenida();}
}
function escribirBienvenida(){
document.write("<H1>Hola a todos</H1>")
}
function pruebaClic()
{
alert("¡ El botón ha sido pulsado !");
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name=form1>
<INPUT name=boton1 type=button value="Pulse aquí">
</FORM>
</BODY></HTML>
  #4 (permalink)  
Antiguo 10/12/2011, 06:41
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: 2 funciones con un solo botón

por que debería de responderte cuando abres temas y no te molestas ni tan siquiera en revisarlos??
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}
  #5 (permalink)  
Antiguo 11/12/2011, 09:38
 
Fecha de Ingreso: febrero-2011
Mensajes: 55
Antigüedad: 13 años, 2 meses
Puntos: 4
Respuesta: 2 funciones con un solo botón

Código PHP:
<HTML>
<
HEAD>
<
SCRIPT language=JavaScript>
onload=init;

function 
init(){
document.form1.boton1.onclick = function(){
                                        
pruebaClic();
                                        
escribirBienvenida();
                                        }
}

function 
escribirBienvenida(){
document.write("<H1>Hola a todos</H1>")
}
function 
pruebaClic(){
alert("¡ El botón ha sido pulsado !");
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="form1">
<INPUT name='boton1' type='button' value="Pulse aquí">
</FORM>
</BODY></HTML> 
al principio es normal equivocarse pero ten muchisimo cuidado ...!!! compara este codigo con el tuyo
  #6 (permalink)  
Antiguo 11/12/2011, 16:29
 
Fecha de Ingreso: agosto-2011
Mensajes: 8
Antigüedad: 12 años, 8 meses
Puntos: 0
Respuesta: 2 funciones con 1 solo botón

Hola.
Con esto de "responder al tema" no sé si estoy respondiendome a mí mismo o a
IsaBelM.
Sí, si que he estado atendiendo a lo que me has contestado, pasando tu código con mis variables y no funciona.
Como no ha habido manera, he simplificado mi código con otras funciones más sencillas. Pero si imprime, me lo borra todo en la pantalla.
Un saludo.

Etiquetas: funcion, funciones, html, input
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 18:39.