JavaScript - No consigo llamar a una función de un archivo .js

 
Vista:
sin imagen de perfil

No consigo llamar a una función de un archivo .js

Publicado por Victor (2 intervenciones) el 29/03/2017 11:16:34
Buenas, tengo los archivos functions.js y RecogeDatos.php. Mi problema es que necesito llamar de el archivo functions.js la función transformarEnEditable() desde RecogeDatos.php. He probado poniendo en la cabecera del head de RecogeDatos.php la ruta y llamar a la función dentro del body en la tabla y también he probado poniendo todo el código de functions.js en RecogeDatos.php después de la etiqueta <body> pero de ninguna forma me lo detecta...Alguna sugerencia?

functions.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var editando=false;
 
function transformarEnEditable(nodo){
//El nodo recibido es SPAN
	alert("llego");
	if (editando == false) {
 
		var nodoTd = nodo.parentNode; //Nodo TD
		var nodoTr = nodoTd.parentNode; //Nodo TR
		var nodoContenedorForm = document.getElementById('contenedorForm'); //Nodo DIV
		var nodosEnTr = nodoTr.getElementsByTagName('td');
		var id = nodosEnTr[0].textContent;
		var Accion = nodosEnTr[1].textContent;
		var Resolucion = nodosEnTr[2].textContent;
		var Fecha = nodosEnTr[3].textContent;
		var opciones = nodosEnTr[4].textContent;
 
		var nuevoCodigoHtml = '<td><input type="text" name="id" id="id" value="'+id+'" size="10"></td>'+
		'<td><input type="text" name="Accion" id="Accion" value="'+Accion+'" size="10"</td>'+
		'<td><input type="text" name="Resolucion" id="Resolucion" value="'+Resolucion+'" size="10"</td>'+
		'<td><input type="text" name="Fecha" id="Fecha" value="'+Fecha+'" size="10"</td>'+;
 
		nodoTr.innerHTML = nuevoCodigoHtml;
 
		nodoContenedorForm.innerHTML = 'Pulse Guardar para guardar los cambios o cancelar para anularlos'+
		'<form name = "formulario" action="guardardatos.php" method="get" onsubmit="capturarEnvio()" onreset="anular()">'+
		'<input class="boton" type = "submit" value="Guardar"> <input class="boton" type="reset" value="Cancelar">';
 
		editando = "true";
 
	}else {
 
		alert ('Solo se puede editar una línea. Recargue la página para poder editar otra fila');
 
	}
}
 
function capturarEnvio(){
 
	var nodoContenedorForm = document.getElementById('contenedorForm'); //Nodo DIV
	nodoContenedorForm.innerHTML = 'Pulse Guardar para guardar los cambios o cancelar para anularlos'+
	'<form name = "formulario" action="guardardatos.php" method="get" onsubmit="capturarEnvio()" onreset="anular()">'+
	'<input type="hidden" name="id" value="'+document.querySelector('#alimento').value+'">'+
	'<input type="hidden" name="Accion" value="'+document.querySelector('#calorias').value+'">'+
	'<input type="hidden" name="Resolucion" value="'+document.querySelector('#grasas').value+'">'+
	'<input type="hidden" name="Fecha" value="'+document.querySelector('#proteina').value+'">'+
	'<input class="boton" type = "submit" value="Guardar"> <input class="boton" type="reset" value="Cancelar">';
 
	document.formulario.submit();
 
}
 
function anular(){
	window.location.reload();
}

RecogeDatos.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<html>
	<head>
		<script type="text/javascript" src="js/functions.js"></script>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<meta charset="utf-8">
		<link rel="stylesheet" href="css/default.css"/>
		<link rel="stylesheet" href="css/normalize.css">
		<link href='http://fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'>
	</head>
 
	<body>
 
		<?php
 
			$con = null;
 
			include ("Conexion.php");
 
			$c = new ConexionBD();
			$con = $c->conectarse();
 
		?>
 
		<h2>Acciones del cliente</h2>
 
		<table border="1" class="tabla" id="TablaAcciones">
 
			<tr class="resultados">
 
				<th>ID</b></th>
 
				<th>Acci&oacute;n</th>
 
				<th>Resoluci&oacute;n</th>
 
				<th>Fecha</th>
 
				<th>Descripci&oacute;n</th>
 
				<th>Opciones</th>
 
			</tr>
 
				 <?php
 
				  $resultado = consultaAcciones($con);
 
				  while($row = sqlsrv_fetch_array($resultado)) { ?>
 
 
					<tr>
 
						<td id="id"><?php echo $row['id_Accion']?></td>
						<td><?php echo $row['Accion']?></td>
						<td><?php echo $row['Resolucion']?></td>
						<td><?php echo $row['Fecha']?></td>
						<td><?php echo $row['Descripcion']?></td>
						<td>
							<div align="center">
								<span onclick="transformarEnEditable(this)"><img src="img/edit.png" width="20" height="20"></span>
								<img src="img/remove.png" width="20" height="20">
							</div>
						</td>
					</tr>
 
				<?php
				}
				?>
				<!--
				<script>
 				function AnyadeFila() {
						 
						//creo una nueva fila
						 
						 
						var fila='<tr><td>&nbsp;</td>'+
						 
						'<td><input type="text" name="Accion[]"></td>'+
						 
						'<td><input type="text" name="Resolucion[]"></td>'+
						 
						'<td><input type="text" name="Fecha[]"></td>'+
						 
						'<td><input type="text" name="Descripcion[]"></td></tr>';
						 
						//añado fila a la tabla
						 
						$('.tabla').append(fila);

					}

				function detectaFila(){

					var TotalFilas= document.getElementById("TablaAcciones").rows.length;


					for (var i = 0; i >= TotalFilas; i++) {
						
					}
				}					 
				</script>-->
 
				<br>
				<br>
				</form>
				<?php
 
				function consultaAcciones($con){
 
					$nom = $_GET["Nombre"];
 
					if($nom!==""){
 
						$tsql = "SELECT C.Cod_Cli,C.Nombre,A.id_Cliente,A.id_Accion,A.id_Estado,A.Accion,A.Resolucion,A.Fecha,E.Descripcion from Clientes C INNER JOIN Acciones A ON c.Cod_Cli = A.id_Cliente INNER JOIN Estados E  ON A.id_Estado = E.id_Estado WHERE Cod_Cli = id_Cliente and Nombre = '".$nom."';";
 
						$stmt = sqlsrv_query($con,$tsql);
 
						if( $stmt === false ){
							echo "Error al ejecutar consulta.</br>";
							die( print_r( sqlsrv_errors(), true));
						}
 
						return $stmt;
						sqlsrv_free_stmt($stmt);
						sqlsrv_close($con);
					}
				}
 
				?>
 
				</table>
 
				<div id="contenedorForm">
	 			</div>
 
				<br>
	</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

No consigo llamar a una función de un archivo .js

Publicado por Victor (2 intervenciones) el 29/03/2017 12:07:45
Solucionado, ha sido un despiste jeje. El error estaba al final de esta línea del archivo.js, el fallo era el + :

'<td><input type="text" name="Fecha" id="Fecha" value="'+Fecha+'" size="10"</td>'+;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
2
Comentar