Rafael Prado
Rafael Prado

Reputation: 21

get the value of an <div> tag

I am interested in when choosing an option from a drop-down list the value of the selected option that stá visualiando in a < div > that value is captured in a javascript variable. The list referred to originated in an AJAX routine that queries a database. On page php , where there is a div shown above . I need your help to take this value from the list.

Upvotes: 2

Views: 71

Answers (1)

georgiaboy82
georgiaboy82

Reputation: 552

Assuming that you meant for your question read the way RightClick explained it in the comments, you need something like this:

window.onload = function() {
var ids = $('.dropdown').map(function(){
    return this.id;
}).get();//Get array of ids


    var options = document.getElementsByClassName('dropdown');
    for(var i = 0; i < options.length; i++) {
        var anchor = options[i];
        anchor.onclick = function() {
            var h = new XMLHttpRequest();
            h.open("GET", "/myDB?q="+ids[i], true);//This should be synchronous
            h.send();
            document.getElementById("responseDiv").innerHTML = h.responseText;
        }
    }
}

`

Upvotes: 1

Related Questions