Matthew Walker Matthew Walker - 1 year ago 94
Javascript Question

JS variable returning object not value

I'm setting a global variable via jQuery as such:

user = $("#user").val();

Specifically without
so that it can be pulled outside of

When I try to pull that variable later all I get is
[object HTMLInputElement]

Here is the code I'm using to pull that variable,

<script type="text/javascript">
document.getElementById("user-login-info").innerHTML = "Hello, "+user;

What am I doing wrong here?

Answer Source

I have checked it and modified a little

$("#login-submit").click(function() {
                    user = $("#user").val();
                    pass = $("#pass").val();
                    var dataString = "user="+user+"&pass="+pass;
                    var linkString = "index.html#home";
                    if (user == "" || pass == "") {
                        alert("Please fill in all fields");
                    else {
                            type: "POST",
                            url: "",
                            data: {user: user, pass: pass},
                            cache: false,
                            success: function(result) {
                                if (result = "1") {
                                    alert("Login Sucess.");
                                    setTimeout(location.href = linkString,1000);
                                else { alert("Username or Password incorrect. Please try again."); }
                    return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download