0

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.

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
4
Views
7 Years
Discussion Span
Last Post by vsmash
0
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;

}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.