Foros del Web » Programando para Internet » Javascript »

Problema con formularios dinamicos

Estas en el tema de Problema con formularios dinamicos en el foro de Javascript en Foros del Web. El formulario es para añadir uan pelicula y que cuando seleccione de genero "Otro" se añada una linea para que especifique el genero con un ...
  #1 (permalink)  
Antiguo 21/03/2008, 11:04
 
Fecha de Ingreso: enero-2008
Mensajes: 381
Antigüedad: 16 años, 3 meses
Puntos: 19
Problema con formularios dinamicos

El formulario es para añadir uan pelicula y que cuando seleccione de genero "Otro" se añada una linea para que especifique el genero con un onChange

Pero el script da un error muy raro y nisiquiera llega a declararse la funcion add que es la que añade la linea

Este es el error que da por el que no se declara

Como podeis ver en el firefox solo dice que la funcion add() no existe


Pero en opera es mas detallado (pero no entiendo que es lo que esta mal)


A ver si me podeis ayudar ya me estoy volviendo loco con este dichoso script

Aqui esta el codigo


Gracias de antemano

EDIT: Dejo aqui el codigo:
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Documento sin t&iacute;tulo</title>
<script language="javascript" type="text/javascript">
 
  function add(){
    alert("añadiendo fila");
    myNewRow = document.getElementById("Form").insertRow(6);
    myNewRow.id=6;
    myNewCell=myNewRow.insertCell(6);
    myNewCell.innerHTML="<td nowrap><b>Especificar Genero</b></td>";
    myNewCell=myNewRow.insertCell(6);
    myNewCell.innerHTML="<td><input type=\"text\" name=\"Genero\" size=\"40\" maxlength=\"100\"></td>";
  }
 
  function remove(obj){
    var oTr = obj;
    while(oTr.nodeName.toLowerCase()!='tr') {
      oTr=oTr.parentNode;
    }
    var root = oTr.parentNode;
    root.removeChild(oTr);
  }
 
  function check(value, obj) {
    if (value == 0) { 
      alert("value es = a 0");
      add();
      var add = "yes";
    }
    else if(add=="yes") remove(obj);
  }
 
</script>
</head>
 
<body>
<form method="post" action="modules.php?name=$module_name&amp;par=AddingGame">
<table width="100%" border="0" cellspacing="3" id="Form">
<tr><td nowrap><b>Titulo</b></td><td><input type="text" name="title" size="40" maxlength="100"></td></tr>
<tr><td nowrap><b>Imagen</b></td><td><input type="file" name="imagen" size="40" maxlength="255"></td></tr>
<tr><td nowrap><b>Link de descarga</b></td><td><input type="text" name="down_link" size="40" maxlength="255"></td></tr>
<tr><td nowrap><b>Codigo para ver Online</b></td><td><input type="text" name="online_link" size="40" maxlength="255"></td></tr>
<tr><td nowrap><b>Genero</b></td><td><select name="genre" onChange="check(this.value, this)"><option value="13">Acción</option><option value="14">Animación</option><option value="15">Aventuras</option><option value="26">Comedia</option><option value="20">Drama</option><option value="24">Ficcion</option><option value="25">Historico</option><option value="22">Policiaca</option><option value="23">Suspense</option><option value="21">Terror</option><option value="0">Otro</option></select></td></tr>
<tr><td nowrap><b>Subgenero</b></td><td><input type="text" name="subgenre" size="40" maxlength="100"></td></tr>
<tr><td nowrap><b>Fecha de estreno</b></td><td><input type="text" name="day" size="2" maxlength="2">
                         <input type="text" name="month" size="2" maxlength="2">
                                               <input type="text" name="year" size="4" maxlength="4">&nbsp;(dia/mes/a&ntilde;o)</td></tr>
<tr><td nowrap><b>Duracion</b></td><td><input type="text" name="duracion" size="40" maxlength="50"></td></tr>
<tr><td nowrap><b>Link de informacion</b></td><td><input type="text" name="infolink" size="40" maxlength="255"></td></tr>
<tr><td nowrap><b>Otra Informacion</b></td><td><input type="text" name="otherinfo" size="40" maxlength="255"></td></tr>
<tr><td nowrap><b>Sinopsis</b></td><td><textarea name="sinopsis" cols="60" rows="10"></textarea></td></tr>
<tr><td nowrap><b>Estrellas</b></td><td><input type="text" name="starts" size="40" maxlength="255"></td></tr>
<tr><td>&nbsp;</td><td><input type="submit" name="submit" value="Agregar"></td></tr>
</table></form>
</body>
</html> 

EDIT:
Este codigo esta mal, si te interesa mira el que he puesto mas abajo

Última edición por El-FeNiX; 22/03/2008 a las 10:13
  #2 (permalink)  
Antiguo 21/03/2008, 16:42
Avatar de derkenuke
Colaborador
 
Fecha de Ingreso: octubre-2003
Ubicación: self.location.href
Mensajes: 2.665
Antigüedad: 20 años, 6 meses
Puntos: 45
Re: Problema con formularios dinamicos

Hola:

Lo que ocurre es que si llamas a una función add, no puedes tener una variable que también se llame add. Recuerda que las funciones también son variables:
Código PHP:
var foo = function() { alert("hola"); }
foo();    // Se puede ejecutar, es una función (variable tipo Function)
foo "bar";
// foo();    //No se puede ejecutar, es una variable tipo String
alert(foo); 
Te recomendaría pegar aquí el código, así queda permanentemente en el foro.


Saludos.
__________________
- Haz preguntas inteligentes, y obtendrás más y mejores respuestas.
- Antes de postearlo Inténtalo y Búscalo.
- Escribe correctamente tus mensajes.
  #3 (permalink)  
Antiguo 22/03/2008, 10:11
 
Fecha de Ingreso: enero-2008
Mensajes: 381
Antigüedad: 16 años, 3 meses
Puntos: 19
Re: Problema con formularios dinamicos

derkenuke, muchas gracias ya he podido solucionar el problema

no he contestado antes porque hasta ahora no he conjseguido hacerlo funcionar, he tenido que modificar algunas cosas mas

Aqui dejo el codigo con las modificaciones que he echo para que funcione por si a alguien le interesa

Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Documento sin t&iacute;tulo</title>
<script language="javascript" type="text/javascript">
	
	function add(){
		NewRow = document.getElementById("Form").insertRow(5);
		NewRow.id=5;
		NewCell=NewRow.insertCell(-1);
		NewCell.innerHTML="<b>Especificar Genero</b>";
		NewCell=NewRow.insertCell(-1);
		NewCell.innerHTML="<input type=\"text\" name=\"Genero\" size=\"40\" maxlength=\"100\">";
	}
	 
	function remove(){
		var oTr = NewRow;
		while(oTr.nodeName.toLowerCase()!='tr') {
			oTr=oTr.parentNode;
		}
		var root = oTr.parentNode;
		root.removeChild(oTr);
	}
	
	function check(value) {
		if (value == 0) { 
			added = "yes";
			add();
		}
		else {
			if(added=="yes") remove();
		}
	}
	
</script>
</head>

<body>
<form method="post" action="modules.php?name=$module_name&amp;par=AddingFilm">
<table width="100%" border="0" cellspacing="3" id="Form">
<tr><td nowrap><b>Titulo</b></td><td><input type="text" name="title" size="40" maxlength="100"></td></tr>
<tr><td nowrap><b>Imagen</b></td><td><input type="file" name="imagen" size="40" maxlength="255"></td></tr>
<tr><td nowrap><b>Link de descarga</b></td><td><input type="text" name="down_link" size="40" maxlength="255"></td></tr>
<tr><td nowrap><b>Codigo para ver Online</b></td><td><input type="text" name="online_link" size="40" maxlength="255"></td></tr>
<tr><td nowrap><b>Genero</b></td><td><select name="genre" onChange="check(this.value)"><option value="13">Acción</option><option value="14">Animación</option><option value="15">Aventuras</option><option value="26">Comedia</option><option value="20">Drama</option><option value="24">Ficcion</option><option value="25">Historico</option><option value="22">Policiaca</option><option value="23">Suspense</option><option value="21">Terror</option><option value="0">Otro</option></select></td></tr>
<tr><td nowrap><b>Subgenero</b></td><td><input type="text" name="subgenre" size="40" maxlength="100"></td></tr>
<tr><td nowrap><b>Fecha de estreno</b></td><td><input type="text" name="day" size="2" maxlength="2">
											   <input type="text" name="month" size="2" maxlength="2">
                                               <input type="text" name="year" size="4" maxlength="4">&nbsp;(dia/mes/a&ntilde;o)</td></tr>
<tr><td nowrap><b>Duracion</b></td><td><input type="text" name="duracion" size="40" maxlength="50"></td></tr>
<tr><td nowrap><b>Link de informacion</b></td><td><input type="text" name="infolink" size="40" maxlength="255"></td></tr>
<tr><td nowrap><b>Otra Informacion</b></td><td><input type="text" name="otherinfo" size="40" maxlength="255"></td></tr>
<tr><td nowrap><b>Sinopsis</b></td><td><textarea name="sinopsis" cols="60" rows="10"></textarea></td></tr>
<tr><td nowrap><b>Estrellas</b></td><td><input type="text" name="starts" size="40" maxlength="255"></td></tr>
<tr><td>&nbsp;</td><td><input type="submit" name="submit" value="Agregar"></td></tr>
</table></form>
</body>
</html> 
Saludos
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 01:43.