Basically i am trying to create a AJAX script in Jquery. but the main problem is that i want to define the variables like this
$(document).ready(function () {
var u = $('#username');
var s = $('#server');
var p = $('#password');
$('#server').keyup(function () {
$.post("connect.php", { s: s.value, u: u.value , p: p.value },
function(data) {
$('#hol').html('checking connection...' + u.value + " " + p.value + " " + s.value + " " + data);
}
);
});
});
But that somehow doesn't work.... it seems rather odd that i have to define the variables with "this" instead of being able to assign them before hand.
the code that works is
$(document).ready(function () {
$('#username').keyup(function () {
var u = this;
$('#password').keyup(function () {
var p = this;
$('#server').keyup(function () {
var s = this;
$.post("connect.php", { s: s.value, u: u.value , p: p.value },
function(data) {
$('#hol').html('checking connection...' + u.value + " " + p.value + " " + s.value + " " + data);
}); });
});
});
});
so my question is basically "How do I make jquery catch the input in the text field and assign it to a variable? like in the first example??" or it doesnt have to be done in the long way?
$('#server, #username, #password')