Jump to content
Fórum Script Brasil
  • 0

Carregando no campo errado


ViniciusJau

Question

Fala moçada..

estou tentando adaptar um codigo de combo dinamico de dois selects para três selects....

O problema é que quando eu seleciono a opção no segundo select ao invés de ele atualizar os dados no terceiro select ele atualiza no segundo select mesmo...

Deu pra entender ? :huh:

Meu código está assim:

/* Busca do primeiro para o segundo select */

function list_dados( valor )

{

http.open("GET", "categorias_busca.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();

// Logo após fazer a verificação, é chamada a função e passada

// o valor à variável global http.

/* Busca do segundo para o terceiro select */

function list_dados2( valor )

{

http.open("GET", "categorias_busca_sub.php?id=" + valor, true);

http.onreadystatechange = handleHttpResponse;

http.send(null);

}

Dai deixei os campos assim:

Primeiro Select:

<select name="categoria" id="categoria" onchange="list_dados(this.value)" class="campo" style="width:180px; height:20px;">

Segundo Select:

<select name="subcategoria" class="campo" onchange="list_dados2(this.value)" style="width:180px; height:20px;">

Terceiro Select:

<select name="categoriafinal" class="campo" style="width:180px; height:20px;">

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...