Uncaught ReferenceError: province_name is not defined
I’m having this error and I don’t know why, because I have used the same steps with other methods and everything is ok. What I want to do is to pass a parameter on a onclick function in venta.php from venta.js, and when the btn is clicked the info must be added on the page.
This is the code for venta.php
JavaScript
x
19
19
1
require_once "../modelos/Disponibilidad.php";
2
$disponibilidad = new Disponibilidad();
3
4
$rspta = $disponibilidad->listarDisponibilidadEstadoDisponible();
5
$data = array();
6
7
while ($reg = $rspta->fetch_object()) {
8
$data[] = array(
9
"0" => '<button class="btn btn-warning" onclick="agregarDetalleDisponibilidad(' . $reg->nombre_provincia . ')"><span class="fa fa-plus"></span></button>',
10
"1" => $reg->nombre_provincia,
11
"2" => $reg->ciudad,
12
"3" => $reg->descripcion,
13
"4" => $reg->fecha_disponible,
14
"5" => $reg->hora_disponible,
15
"6" => $reg->estado
16
17
);
18
}
19
Code for venta.js
JavaScript
1
19
19
1
function agregarDetalleDisponibilidad(nombreProvincia) {
2
if (idDisponibilidad != "") {
3
var filaDisponibilidad =
4
'<tr class="filasDisponibilidad" id="disponibilidad' + contDisponibilidad + '">' +
5
'<td><button type="button" class="btn btn-danger" onclick="eliminarDetalleDisponibilidad(' + contDisponibilidad + ')">X</button></td>' +
6
'<td><input type="hidden" name="iddisponibilidad[]" value="' + idDisponibilidad + '">' + nombreProvincia + '</td>' +
7
'<td>' + nombreCiudad + '"></td>' +
8
'<td>' + tipoVehiculo + '"></td>' +
9
'<td>' + fechaDisponible + '"></td>' +
10
'<td>' + horaDisponible + '"></td>' +
11
'</tr>';
12
contDisponibilidad++;
13
detalleDisponibilidad++;
14
$('#detalleSeleccionDisponibilidad').append(filaDisponibilidad);
15
} else {
16
alert("Error al ingresar el detalle, revisar los datos de la disponibilidad ");
17
}
18
}
19
Advertisement
Answer
Strings inside of functions need to be quoted. Change your code from
JavaScript
1
2
1
"0" => '<button class="btn btn-warning" onclick="agregarDetalleDisponibilidad(' . $reg->nombre_provincia . ')"><span class="fa fa-plus"></span></button>',
2
to
JavaScript
1
2
1
"0" => '<button class="btn btn-warning" onclick="agregarDetalleDisponibilidad('' . $reg->nombre_provincia . '')"><span class="fa fa-plus"></span></button>',
2