Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal já tentei de várias maneiras fazer esse envio de duas variaves através de um <select>
Já tentei usar FUNÇÃO explode e depois pegar cada uma das informações tipo ID e CATEGORIA
Mas estou usando ajax, e ele não aceita fazer isso!
Eu preciso passar as seguintes variaveis:
id_categoria = está chegando perfeitamente (É o nome do primeiro select, onde exibe as categorias)
categoria = Não consigo fazer esse campo ir para o banco de dados.
id_subcategoria = Não consigo fazer esse campo ir para o banco de dados.
subcategoria = está chegando perfeitamente (É o nome do segundo select, onde exibe as subcategorias)
Gostaria de passar os dois dados que estão faltando!
Alguém poderia me ajudar?
Estou usando os seguintes arquivos
form.php Aqui aparece as 2 combobox categoria e subcategoria
>
<?php
$con = mysql_connect("localhost", "root", "root");
mysql_select_db("rally");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function list_dados( valor )
{
http.open("GET", "result.php?id=" + valor, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function handleHttpResponse()
{
campo_select = document.forms[0].subcategoria;
if (http.readyState == 4) {
campo_select.options.length = 0;
results = http.responseText.split(",");
for( i = 0; i < results.length; i++ )
{
string = results.split( "|" );
*campo_select.options** = new Option( string[0], string[1] );*
}
}
}
function getHTTPObject() {
var req;
try {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
if (req.readyState == null) {
req.readyState = 1;
req.addEventListener("load", function () {
req.readyState = 4;
if (typeof req.onReadyStateChange == "function")
req.onReadyStateChange();
}, false);
}
return req;
}
if (window.ActiveXObject) {
*var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];*
*for (var i = 0; i < prefixes.length; i++) {*
try {
*req = new ActiveXObject(prefixes** + ".XmlHttp");*
*return req;*
} catch (ex) {};
}
}
} catch (ex) {}
alert("XmlHttp Objects not supported by client browser");
}
var http = getHTTPObject();
*</script>*
*</head>*
*<body>*
*<select name="id_categoria" onChange="list_dados( this.value )">*
*<?php*
*$consulta = mysql_query("SELECT * FROM categcompeticao ORDER BY categoria DESC");*
while( $row = mysql_fetch_assoc($consulta) )
{
echo "<option value=\"{$row['id_categoria']}\">{$row['categoria']}</option>\n";
}
*?>*
*</select>*
*</p>*
*<p><select name="subcategoria"></select>*
*</p>*
*</body>*
*</html>*
*result.php** Esse é o arquivo que processa e volta os dados para a combo subcategoria*
>
*<?php header("Content-Type: text/html; charset=iso-8859-1",true) ?>*
*<?php*
$con = mysql_connect("localhost", "root", "root");
mysql_select_db("rally");
*$categoria = addslashes(trim($_GET["id"]));*
*$consulta = mysql_query("SELECT * FROM subcategcompeticao WHERE id_categoria = '$categoria' ORDER BY subcategoria ASC" );*
while( $row = mysql_fetch_assoc($consulta) )
{
echo $row["subcategoria"] . "|" . $row["subcategoria"] . ",";
}
?>
Carregando comentários...