Monday, 30 September 2013

Getting div id by GET in Javascript

Getting div id by GET in Javascript

Ciao
I need to create a dynamic form based on user selections.
I.e. in the first form field I select "John Smith", this will populate
(through an external php/mysql file ) the second select field "Artist,
Carpenter, Other", if I choose Artist I populate the third select field
with "Singer, Painter, Sculptor" and so on
Giving my incompetence on javascript, I spent the morning googling for
scripts and I found a cool tutorial here
It works, it's clean, but it updates only the div with id txtResult, which
is statically included in the js file (see lines 19 and 31 of
ajax_req.js). I thought I could pass the id name by GET, but I don't know
how to make the script recognize the variable.
This is the code:
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtResult").innerHTML=
xmlHttp.responseText;
}
}
I had in mind to pass by GET the id name and have something like this:
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("GET[idName]").innerHTML=
xmlHttp.responseText;
}
}
Can you please help me? I could change script too if you happen to know
something better
Ciao and thank you,
Ed

No comments:

Post a Comment