My question is pretty simple... I have the code posted above and it
doesn't work. To test the problem, load the page (of course lol),
click on "Submit" and you'll see a message stating what the script is
going to do next, then, click on "Show!". You'll see the value "null"
and I don't understand why, I think it should have been "Hello World".

The code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jqForm Test</title>
<script type="text/javascript" src="libs/jquery.js"></script>
<script type="text/javascript" src="libs/jquery.form.js"></script>
<script type="text/javascript">
        (function($) {
                $.admin = {
                        init: function() {
                                $('form#form-login').ajaxForm({
                                        beforeSubmit: this.ajax.request
                                });
                        }
                }
        })(jQuery);

        (function($) {
                $.admin.ajax = {
                        someVar: null,
                        request: function(formData, jqForm, options) {
                                alert("Setting someVar = Hello World.")

                                this.someVar = "Hello World";

                                return false; // we are testing, don't really 
need to submit the
form
                        }
                }
        })(jQuery);

        $(document).ready(function() {
                $.admin.init();

                $('input#show').click(function() {
                        alert("someVar: " + $.admin.ajax.someVar);
                });
        });
</script>
</head>
<body>
        <form id="form-login" action="index.php" method="post">
                <input name="internal" type="hidden" value="login" />
                <strong>{FormLabel:Username}:</strong><br />
                <input name="login_username" type="text" size="25" /><br />
                <br />
                <strong>{FormLabel:Password}:</strong><br />
                <input name="login_password" type="password" size="25" /><br />
                <br />
                <input type="submit" value="Submit" />
                <input id="show" type="button" value="Show!" />
        </form>
</body>
</html>

If I replace:

this.someVar = "Hello World";

With:

$.admin.ajax.someVar = "Hello World";

It will work, but this makes no sense to me. I should be able to use
this, that's what makes sense on my head... What am I missing?

Reply via email to