
valor de option en ajax
Publicado por mario (3 intervenciones) el 20/02/2016 07:42:26
buenas, tengo un problema, el problema es que tengo un select y al tener el valor de entero en option value ='1' todo bien pero al tener un value = "ud-11-11" no me envia nada, me podrian ayudar.
solo intento imprimir en la pantalla los datos de la tabla.
otro archivo
ajax.php
ayudenme porfavor!
solo intento imprimir en la pantalla los datos de la tabla.
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
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","ajax.php?q="+str,true);
xmlhttp.send();
}
}
</script>
<?php
error_reporting (E_ALL ^ E_DEPRECATED);
$conexion = mysql_connect("localhost", "root", "");
if (!$conexion) {
echo "No pudo conectarse a la BD: " . mysql_error();
exit;
}
if (!mysql_select_db("pres")) {
echo "No ha sido posible seleccionar la BD: " . mysql_error();
exit;
}
$sentancia = "select * from materias";
$query = mysql_query($sentancia,$conexion);
?>
<form >
<select name="M" onchange="showUserr(this.value)">
<option value="">Seleccionar:</option>
<?php while($lista = mysql_fetch_array($query)) { ?>
<option value="<?php echo $lista[0] ?>" ><?php echo $lista[0] ?></option>
<?php } ?>
</select>
</form>
<div id="txtHint"><b>Informacion </b></div>
otro archivo
ajax.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
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
$q = intval($_GET['q']);
$con2 = mysqli_connect('localhost','root','');
if (!$con2) {
die('Could not connect: ' . mysqli_error($con2));
}
mysqli_select_db($con2,"prestamo");
$sql="SELECT * FROM materias WHERE IDMat = '$q'";
$result = mysqli_query($con2,$sql);
echo "<table>
<tr>
<th>Numero de materia</th>
<th>Nombre</th>
</tr>";
while($row2 = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row2[0] . "</td>";
echo "<td>" . $row2[1] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con2);
?>
</body>
</html>
ayudenme porfavor!
Valora esta pregunta


0