Javascript don't see diference between 2 textarea ids

83 views Asked by At

I have this function:

function sendCommand(id, ip, command) {
    var xmlhttp = makeRequestObject();
    var file = 'http://example.com/ajaxaccessdata.php?ip=';
    xmlhttp.open('GET', file + ip + '&command=' + command, true);
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var content = xmlhttp.responseText;
            if (content) {
                document.getElementById('result' + id).value = content;
            }
        }
    }
    xmlhttp.send(null)
}

And i have n textarea with IDs 'result1', 'result2', ..., 'resultn'.
And when i call function sendCommand my function put result in all textarea, so result for sendCommand(1, 'localhost', 'A') will be put in all textarea not only in result.
Any ideas ?
Thanks

1

There are 1 answers

0
Shane On
xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var content = xmlhttp.responseText;
        if (content) {
            var x = document.getElementsByName('result');
            x[id+1].value = content;
        }
     }
}