obtener valor de un campo cargado en un div
Publicado por Francisco (3 intervenciones) el 14/12/2017 06:26:22
buenas noches tengo el siguiente script :
y lo cargo en el siguiente html:
mi pregunta es como puedo obtener los valores de los div para luego hacer un insert en una base de datos en 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
$(document).ready(function() {
$.ajax({
dataType: "json",
data: [],
url: "https://ubicaciones.paginasweb.cr/provincias.json",
type: 'GET',
crossDomain: true,
success: function(data) {
agregarProvincias(data);
}
});
$(document).on('change', '#provincia > select', function() {
var provincia = this.value;
$.ajax({
dataType: "json",
url: "https://ubicaciones.paginasweb.cr/provincia/" + provincia + "/cantones.json",
data: {},
success: function(data) {
agregarCantones(data);
}
});
});
$(document).on('change', '#canton > select', function() {
var provincia = $('select#provincia').val();
var canton = this.value ;
$.ajax({
dataType: "json",
url: "https://ubicaciones.paginasweb.cr/provincia/" + provincia + "/canton/" + canton + "/distritos.json",
data: {},
success: function(data) {
agregarDistritos(data);
}
});
});
function agregarProvincias(data) {
var html = "<select id='provincia'>";
for (key in data) {
html += "<option value='" + key + "'>" + data[key] + "</option>";
}
html += "</select";
$('#provincia').html(html);
}
function agregarCantones(data) {
var html = "<select>";
for (key in data) {
html += "<option value='" + key + "'>" + data[key] + "</option>";
}
html += "</select";
$('#canton').html(html);
}
function agregarDistritos(data) {
var html = "<select>";
for (key in data) {
html += "<option value='" + key + "'>" + data[key] + "</option>";
}
html += "</select";
$('#distrito').html(html);
}
});
y lo cargo en el siguiente html:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html>
<head>
<title>Obteniendo las provincias</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<meta charset="utf-8">
<script type="text/javascript" src="js/js_pronvincias_cantontes_distritos.js"></script>
</head>
<br>
<div id="provincia"></div>
<div id="canton"></div>
<div id="distrito"></div>
</body>
</html>
mi pregunta es como puedo obtener los valores de los div para luego hacer un insert en una base de datos en php.
Valora esta pregunta
-1