My problem is very easy. I have written the following PHP code to generate the arrays of textareas:

for ($i=0; $i<length; $i++)
{
echo '<textarea type="text" name="username'. $i.'" cols="60" rows="4" onkeydown="check_username(this.form.username'. $i. '.value)">'. $sentences_data [$i]. '</textarea> <span id="username_label"></span><br/>';
}

The Java function is

function check_username(username) {
    if (ajax) {

            ajax.open('get','testuser.php?username=' + encodeURIComponent(username));

            ajax.onreadystatechange = handle_check;

            ajax.send(null);                


    }
    else
    {
        alert("Ajax not created");
        document.getElementId('username_label').innerHTML = 'Dummy text';
    }
}

function handle_check() {
    if((ajax.readyState == 4) && (ajax.status == 200)) {

        document.getElementById('username_label').innerHTML = ajax.responseText;

    }
}

Actually, when i edit the textarea data it returns the validated data back to the PHP just below the first textarea. But i want all the validated data on right side of each textarea. Please suggest me the changes in my code both in php and java code i have demonstrated above.

for ($i=0; $i<length; $i++)
{
echo '<textarea type="text" name="username'. $i.'" cols="60" rows="4" onkeydown="check_username(this.form.username'. $i. '.value,'.$i.')">'. $sentences_data [$i]. '</textarea> <span id="username_label'.$i.'" style="float:right;"></span><br/>';
}
function check_username(username, i) {
if (ajax) {

ajax.open('get','testuser.php?username=' + encodeURIComponent(username));

ajax.onreadystatechange = handle_check;

ajax.send(null); 


}
else
{
alert("Ajax not created");
document.getElementId('username_label'+i).innerHTML = 'Dummy text';
}
}

function handle_check() {
if((ajax.readyState == 4) && (ajax.status == 200)) {

document.getElementById('username_label'+i).innerHTML = ajax.responseText;

}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.