Olá, a todos...
Estou com um problema na variavel dest_combo. ela vem de uma pagina php no evento onChange na funcao ajaxComboBox('url', 'cidades');
O erro é o seguinte:
Erro: document.getElementById('dest_combo').innerHTML = ""; é nulo ou não é um objeto;
________________________________________________________________________________________________________
var HttpReq = null;
var dest_combo = null;
function ajaxComboBox(url, comboBox){
dest_combo = comboBox;
var indice = document.getElementById('estados').selectedIndex;
var sigla = document.getElementById('estados').options[indice].getAttribute('value');
url = url + '?uf=' + sigla;
if(document.getElementById){
if(window.XMLHttpRequest){
HttpReq = new XMLHttpRequest();
HttpReq.onreadystatechange = XMLHttpRequestChange;
HttpReq.open("GET", url, true);
HttpReq.send(null);
}
else
if(window.ActiveXObject){
HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
if(HttpReq){
HttpReq.onreadystatechange = XMLHttpRequestChange;
HttpReq.open("GET", url, true);
HttpReq.send();
}
}
}
}
function XMLHttpRequestChange() {
if(HttpReq.readyState == 1){
document.getElementById('conteudo').innerHTML = "BUSCANDO";
}
if (HttpReq.readyState == 4 && HttpReq.status == 200){
document.getElementById('conteudo').innerHTML = "";
var result = HttpReq.responseXML;
var cidades = result.getElementsByTagName("nome");
document.getElementById('dest_combo').innerHTML = "";
for(var i=0;i<cidades.length;i++) {
var new_opcao = create_opcao(cidades[i]);
document.getElementById('dest_combo').appendChild(new_opcao);
}
}
}
function create_opcao(idade){
var new_opcao = document.createElement("option");
var texto = document.createTextNode(cidades.childNodes[0].data);
new_opcao.setAttribute("value",cidades.getAttribute("id"));
new_opcao.appendChild(texto);
return new_opcao;
}
________________________________________________________________________________________________________

Problemas Com Uma Variavel
Started By Guilherme Ajax, 28/06/2007, 09:12
6 replies to this topic
#1
Posted 28/06/2007, 09:12
#2
Posted 28/06/2007, 10:06
Deixa eu ver se eu entendi, você manda a variavel de uma tela para outra via PHP e pretende pegar pelo JS?
Você tem que colocar essa variavel em algum lugar para poder pegar via JS por uma propriedade, seila...
Faz sentido?
Abraços
Você tem que colocar essa variavel em algum lugar para poder pegar via JS por uma propriedade, seila...
Faz sentido?
Abraços
Procurando freelancer
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
#3
Posted 28/06/2007, 12:00
Então deixa eu explicar melhor né rsrsrs, mals.
Eu utilizo uma pagina "php" - (ela apenas tem a ext .php porem nenhuma funcionalidade com o banco). Com um form, e em um dos combo(que vai atualizar o outro), criei um evento onChange, nesse evento chamei a funcao ajaxComboBox(), e usei como parametros a url de uma pagina php, e o id da comboBox que ira ser atualizada.
Entao ficou assim na pagina "php"
______________________________________________________________________________________________________
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Teste AJAX</title>
<script type="text/javascript" src="02.js"></script>
</head>
<body style="margin:20px;">
<h2>Selecione uma cidade</h2>
<form>
<select name="estados" id="estados" onChange="ajaxComboBox('01_cidades.php','cidades')">
<option selected="selected" value="NDA">-- Estados --</option>
<option value="MT">Mato Grosso</option>
<option value="SP">São Paulo</option>
</select>
<select name="cidades" id="cidades">
<option>-- Escolha um Estado --</option>
</select>
</form>
<div id="conteudo"></div>
</body>
</html>
______________________________________________________________________________________________________
E a pagina do banco... assim
______________________________________________________________________________________________________
<?php
header("Content-type: text/xml; charset=ISO-8859-1");
print '<?xml version="1.0" encoding="ISO-8859-1"?>';
?>
<cidades>
<?php
$link = mysql_pconnect("127.0.0.1", "root", "squirrel")
or die("Não pude conectar: " . mysql_error());
mysql_select_db('checklist2', $link) or die ('Não foi possível usar db: ' . mysql_error())
$result = mysql_query("SELECT cidades.id,cidades.nome FROM estados,cidades WHERE
estados.sigla = '{$_GET['uf']}' AND estados.id = cidades.id_estado
ORDER BY cidades.nome"
or die("Query invalida: " . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("<nome id=\"%d\">%s</nome>\n", $row[0],$row[1]);
}
mysql_close($link);
?>
</cidades>
_______________________________________________________________________________________________________
vlw, pela atençao ^^
Eu utilizo uma pagina "php" - (ela apenas tem a ext .php porem nenhuma funcionalidade com o banco). Com um form, e em um dos combo(que vai atualizar o outro), criei um evento onChange, nesse evento chamei a funcao ajaxComboBox(), e usei como parametros a url de uma pagina php, e o id da comboBox que ira ser atualizada.
Entao ficou assim na pagina "php"
______________________________________________________________________________________________________
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Teste AJAX</title>
<script type="text/javascript" src="02.js"></script>
</head>
<body style="margin:20px;">
<h2>Selecione uma cidade</h2>
<form>
<select name="estados" id="estados" onChange="ajaxComboBox('01_cidades.php','cidades')">
<option selected="selected" value="NDA">-- Estados --</option>
<option value="MT">Mato Grosso</option>
<option value="SP">São Paulo</option>
</select>
<select name="cidades" id="cidades">
<option>-- Escolha um Estado --</option>
</select>
</form>
<div id="conteudo"></div>
</body>
</html>
______________________________________________________________________________________________________
E a pagina do banco... assim
______________________________________________________________________________________________________
<?php
header("Content-type: text/xml; charset=ISO-8859-1");
print '<?xml version="1.0" encoding="ISO-8859-1"?>';
?>
<cidades>
<?php
$link = mysql_pconnect("127.0.0.1", "root", "squirrel")
or die("Não pude conectar: " . mysql_error());
mysql_select_db('checklist2', $link) or die ('Não foi possível usar db: ' . mysql_error())
$result = mysql_query("SELECT cidades.id,cidades.nome FROM estados,cidades WHERE
estados.sigla = '{$_GET['uf']}' AND estados.id = cidades.id_estado
ORDER BY cidades.nome"
or die("Query invalida: " . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("<nome id=\"%d\">%s</nome>\n", $row[0],$row[1]);
}
mysql_close($link);
?>
</cidades>
_______________________________________________________________________________________________________
vlw, pela atençao ^^
#4
Posted 28/06/2007, 12:30
Então, o problema é o seguinte, quando você usa innerHTML no dest_combo, ele procura o OBJ dest_combo como camada e tenta escrever o texto, porém você não tem esse objeto na tela (ele não existe) então ocorre o erro de não encontrar.
<div id='dest_combo'></div>
Entendeu?
PS.: eu tenho esse tutorial escrito para JQuery Framework com ajax também. No meu blog.
Abraços
<div id='dest_combo'></div>
Entendeu?
PS.: eu tenho esse tutorial escrito para JQuery Framework com ajax também. No meu blog.
Abraços
Edição feita por: silici0, 28/06/2007, 12:31.
Procurando freelancer
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
#5
Posted 28/06/2007, 13:09
Vlw... mas como ainda sou newbie...
Queria saber se tem como fazer para funcionar utilizando esses codigos, pois nao sei como trabalhar com frameworks =[...
Flw
Queria saber se tem como fazer para funcionar utilizando esses codigos, pois nao sei como trabalhar com frameworks =[...
Flw
Edição feita por: Guilherme Ajax, 28/06/2007, 13:14.
#6
Posted 28/06/2007, 17:07
Tem claro, mas pelo geito você copiou esse código de algum lugar, então tudo 'diferente', escrevendo onde não existe, chamando coisa diferentes, atribuindo valores diferentes.. ai fica dificil né?
Abraços
Abraços
Procurando freelancer
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
#7
Posted 29/06/2007, 11:23
Sim sim, este não é o que estou montando, esse é um tutorial que tinha na internet.
Usei ele para ver como funcionava, mas acabou não funcionando.
Mas tudo bem, agora meio que entendi o pq, entao queria fazer outra pergunta.
O que estou fazendo estou tendo problemas na hora de criar "campos" para chamar o arquivo XML.
Exemplo
Fiz uma pagina que conecta com o banco assim.:
<?php
header("Content-type: text/xml; charset=ISO-8859-1");
echo'<?xml version="1.0" encoding="ISO-8859-1"?>';
?>
<?php
$conexao = mysql_connect("127.0.0.1,"","") or die(mysql_error());
$banco = mysql_select_db("check",$conexao) or die(mysql_error());
?>
<ret>
<?php
$nome = "";
$nome = $_GET['nome'];
mysql_query("INSERT INTO nome(nom) VALUES('$nome')");
$sql = "SELECT * from nome";
$qry = mysql_query($sql);
$reg = mysql_num_rows($qry);
if($reg){
for($i=0;$i<$reg;i++){
$nomes = mysql_result($qry, $i, "nom");
echo"<nomec>$nomes</nomec>\n";
}
}
mysql_close($conexao);
?>
</ret>
Queria perguntar se está maneira esta certa.
E se caso estiver, como trabalho com a informação que é retornada.
Usei ele para ver como funcionava, mas acabou não funcionando.
Mas tudo bem, agora meio que entendi o pq, entao queria fazer outra pergunta.
O que estou fazendo estou tendo problemas na hora de criar "campos" para chamar o arquivo XML.
Exemplo
Fiz uma pagina que conecta com o banco assim.:
<?php
header("Content-type: text/xml; charset=ISO-8859-1");
echo'<?xml version="1.0" encoding="ISO-8859-1"?>';
?>
<?php
$conexao = mysql_connect("127.0.0.1,"","") or die(mysql_error());
$banco = mysql_select_db("check",$conexao) or die(mysql_error());
?>
<ret>
<?php
$nome = "";
$nome = $_GET['nome'];
mysql_query("INSERT INTO nome(nom) VALUES('$nome')");
$sql = "SELECT * from nome";
$qry = mysql_query($sql);
$reg = mysql_num_rows($qry);
if($reg){
for($i=0;$i<$reg;i++){
$nomes = mysql_result($qry, $i, "nom");
echo"<nomec>$nomes</nomec>\n";
}
}
mysql_close($conexao);
?>
</ret>
Queria perguntar se está maneira esta certa.
E se caso estiver, como trabalho com a informação que é retornada.
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)