quiero que una vez que se mete el código postal mediante AJAX informe el campo POBLACION
Publicado por berfer (2 intervenciones) el 22/04/2020 01:26:32
Hola, Antes de nada decir que soy muy nuevo en AJAX, por si el fallo es simple, que es lo que me temo.
Tengo un formulario, y quiero que una vez que se mete el código postal mediante AJAX informe el campo POBLACION, pero nada de nada.
La función donde tengo el código de AJAX se llama recupera_codpos_poblacion (para localizarlo mas fácilmente), el php al que llama el AJAX lo único que le puse es un echo "PRUEBA"; sin mas.
_______________________________________
código del php que tiene el Ajax
------------------------------
código de buscarpoblacion.php
Tengo un formulario, y quiero que una vez que se mete el código postal mediante AJAX informe el campo POBLACION, pero nada de nada.
La función donde tengo el código de AJAX se llama recupera_codpos_poblacion (para localizarlo mas fácilmente), el php al que llama el AJAX lo único que le puse es un echo "PRUEBA"; sin mas.
_______________________________________
código del php que tiene el Ajax
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
$accion = $_GET['accion'];
include("..\lib\js\libreria_js.php");
?>
<html lang="es" xml:lang="es">
<head>
<meta charset="utf-8" name="TERCEROS" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
TERCEROS
</title>
<link rel="stylesheet" href=".\css\terceros.css" type="text/css"/>
<script>
function validar (formulario)
{
alert("ENTRA");
if (validarDNI(formulario.dni.value) && validar_telefono(formulario.telefono.value)) {
return true;
} else {
return false;
}
}
function buscar ()
{
var frm = document.formulariotercero;
frm.action = "terceros.php";
frm.submit();
}
function recupera_codpos_poblacion ()
{
var frm = document.formulariotercero;
//var codpos = frm.codpostal.value;
var codpos = document.getElementById('codpostal').value;
alert ("ENTRA VALIDAR COD POSTAL");
alert(codpos);
//alert (document.getElementById('codpostal').value);
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
alert ("SALE DEL IF");
if (codpos=="") {
document.getElementById('poblacion').value = "vacio";
alert("no entra ajax");
} else {
alert("entra ajax");
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
alert("ENTRA");
document.getElementById('poblacion').value.innerHTML = this.responseText;
//document.getElementById('poblacion').value.innerHTML = "VALE";
}else{
document.getElementById('poblacion').value.innerHTML = "NO VALE";
}
xmlhttp.open("GET","buscarpoblacion.php",true);
xmlhttp.send();
}
/*frm.action = "buscarpoblacion.php";
frm.submit();*/
//document.getElementById('poblacion').value = "carajo";
}
/* if formulario.codpostal.value != "") {
alert("INFORMADO");
}else {
alert ("VACIO");
}
*/
//document.getElementById('showId').value=document.getElementById('food').value;
}
</script>
</head>
<body>
<div id="contenedor_tercero">
<div id="titulo_y_funcionalidades_terceros">
<?php
if ($accion == "buscar") {
echo '<div id="titulo">
<h2>BUSCAR TERCEROS</h2>
</div>';
}
if ($accion == "insertar") {
echo '<div id="titulo">
<h2>INSERTAR TERCEROS</h2>
</div>';
}
?>
</div>
<div id="resultados_terceros">
<div id="resultados_terceros_formulario">
<!-- Si vamos a buscar formamos este formulario-->
<?php if ($accion == "buscar") {
echo '<form action="" method="get" name="formulariotercero">';
} ?>
<!--Si vamos a insertar hacemos este otro formulario-->
<?php if ($accion == "insertar") {
echo '<form enctype="multipart/form-data" method="post" name="formulariotercero"
onsubmit="return validar(this) ;" action="insertar_tercero.php">';
} ?>
<ul>
<li class="izquierda">
<label class="titulo" for="nombre">Datos Personales </label>
<div>
<span class="cuarto">
<label for="codigo">Codigo</label>
<input type= "text" id="codigo" name="codigo" value="" required />
</span>
<span class="mitad">
<label for="nombre">Nombre</label>
<input id="nombre" name="nombre" value="" required/>
</span>
<span class="cuarto">
<label for="nif">Nif</label>
<input id="nif" name="dni" value="" onblur="validarDNI(this.value)" required/>
</span>
</div>
<div>
<span class="cuarto">
<label for="telefono">Telefono</label>
<input id="telefono" name="telefono" value="" />
</span>
<span class="mitad">
<label for="email">E-mail</label>
<input type="email" id="email" name="email" value="" />
</span>
<span class="cuarto">
<label for="matricula">Matricula</label>
<input id="matricula" name="matricula" value="" />
</span>
</div>
</li>
<li class="izquierda">
<label class="titulo" for="nombre">Direccion Facturacion </label>
<div>
<span class="direccion">
<label for="dirfac">Direccion Factura</label>
<input id="dirfac" name="dirfac" required value="" />
</span>
<span class="codpostal">
<label for="codpostal">Cod. Postal</label>
<input id="codpostal" name="codpostal" value="" onblur="recupera_codpos_poblacion()" />
<a href="pagina_que_carga"> <img width = "10" height="10" src="../imagenes/simbolo_mas.jpg"/></a>
</span>
<span class="pobpro">
<label for="poblacion">Poblacion</label>
<input id="poblacion" name="poblacion" value="" />
</span>
<span class="pobpro">
<label for="provincia">Provincia</label>
<input id="provincia" name="provincia" value="" />
</span>
</div>
</li>
<li class="izquierda">
<label class="titulo" for="nombre">Direccion Suministro </label>
<div>
<span class="direccion">
<label for="dirfac">Direccion Suministro</label>
<a href="pagina_que_carga"> <img width = "10" height="10" src="../imagenes/simbolo_mas.jpg"/></a>
<input id="dirfac" name="dirfac" required value="" />
</span>
<span class="codpostal">
<label for="codpostal">Cod. Postal</label>
<input id="codpostal" name="codpostal" value="" />
</span>
<span class="pobpro">
<label for="poblacion">Poblacion</label>
<input id="poblacion" name="poblacion" value="" />
</span>
<span class="pobpro">
<label for="provincia">Provincia</label>
<input id="provincia" name="provincia" value="" />
</span>
</div>
</li>
<li class="izquierda">
<label class="titulo" for="nombre">Datos Varios</label>
<div>
<span class="quinto">
<label for="tipbon">Tipo Bonificacion</label>
<input id="tipbon" name="tipbon" value="" />
</span>
<span class="quinto">
<label for="tipter">Tipo Tercero</label>
<input id="tipter" name="tipter" value="" />
</span>
<span class="quinto">
<label for="tipfac">Tipo Factura</label>
<input id="tipfac" name="tipfac" value="" />
</span>
<span class="quinto">
<label for="forpag">Forma Pago</label>
<input id="forpag" name="forpag" value="" />
</span>
<span class="quinto">
<label for="tippag">Tipo Pago</label>
<input id="tippag" name="tippag" value="" />
</span>
</div>
<div id="varios">
<span class="tercio">
<label for="fecalt">Fecha Alta</label>
<input id="fecalt" name="fecalt" value="" />
</span>
<span class="tercio">
<label for="fecultcom">Fecha Ultima Compra </label>
<input id="fecultcom" name="fecultcom" value="" />
</span>
<span class="tercio">
<label for="cuecon">Cuenta Contable</label>
<input id="cuecon" name="cuecon" value="" />
</span>
</div>
<div>
<span class="tercio">
<label for="alerta">Alerta</label>
<a href="pagina_que_carga"> <img width = "10" height="10" src="../imagenes/simbolo_mas.jpg"/></a>
<input id="alerta" name="alerta" value="" />
</span>
<span class="tercio">
<label for="clicre">Cliente con Credito</label>
<input id="clicre" name="clicre" value="" />
</span>
<span class="tercio">
<label for="cueban">Cuenta Bancaria</label>
<a href="pagina_que_carga"> <img width = "10" height="10" src="../imagenes/simbolo_mas.jpg"/></a>
<input id="cueban" name="cueban" value="" />
</span>
</div>
</li>
</ul>
</div>
</div>
<?php
if ($accion == "buscar") {
echo '<div id="buscar" style='."position:relative".'>
<input type="button" value="Buscar" onclick="buscar()" />
</div>';
}
if ($accion == "insertar") {
echo '<div id="insert" style='."position:relative".'>
<input type="submit" name="alta" value=" Insertar " />
</div>';
}
?>
</form>
</div>
</body>
</html>
------------------------------
código de buscarpoblacion.php
1
2
3
4
5
<?php
echo ("ok");
?>
Valora esta pregunta


0