Hi,
      I just started learning prototype, and I encountered a problem
while trying Event.observe(window,'load',func);
When I try to run the code below, I get null for formObject. Shouldn't
the class be created only after the body loads ? It behaves as though,
the function creates an instance of the class Login even before the
window load runs. How can I run this code correctly ?
 My aim is to make the Login class listen to the submit event of the
siginForm and retrieve the values in the form.

//======== login.html ====================
<html>
        <title> Hello world</title>
        <script type="text/javascript" src="prototype.js"></script>
        <script type="text/javascript" src="newClass.js"></script>
        <script type="text/javascript">
                Event.observe(window, 'load',function(){
                        new Login('signinForm').register();
                }, false);
        </script>
        <body>
                <form name="signinForm" method="POST" action="">
                        UserName :<input type="text" name="username" 
id="username"/><br/>
                        Password :<input type="text" name="password" 
id="password"/><br/>
                        <input type="submit" value="Submit form"/>
                </form>
        </body>
</html>


//=======newClass.js=================
var Login = Class.create({
        initialize: function(formName){
                alert(formName);
                this.formObject = $(formName);
                alert(this.formObject);
                this.uName=this.formObject.username;
                this.pass=this.formObject.password;
        },
        loginValidate: function(){
                alert("Login action performed. username => "+this.uName.value
+"password => "+this.pass.value);
        },
        register: function(){
                 this.formObject.observe('submit',this.loginValidate);
        }
});


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to rubyonrails-spinoffs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to