On Apr 18, 11:55 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi There,
>
> First my environment:
> Firefox 2.0.0.3 on Linux (Extensions: Firebug, Webdeveloper,
> Aardvark)
>
> I have a webpage (XHTML 1.0 Transitional) in which after clicking on a
> link,
> I load a little <form> via Ajax.Updater.
>
> The form contains buttons which when clicked will
> call a javascript function defined in the initial webpage.
>
> One of these JS functions is:
>
> function enable_form_edit(aform) {
>
> alert(Prototype.Version);
> Form( aform ).enable();
>
> }
>
> the onclick which calls enable_form_edit() is:
>
> onclick="enable_form_edit($(this).up('FORM'));"
Consider:
onclick="enable_form_edit(this.form);"
but if all the function does is enable the form, why not:
onclick="$(this.form).enable();"
> The result is that the alert() actually displays the prototype version
> that I have (1.5.1_rc2) but I get this error on my Firebug console:
>
> >> Form is not a function
> >> Form(aform).enable();
>
> which is pointing to the JS function above.
Because Form isn't a function, it's a plain object with some
properties. Look at line 2548:
var Form = {
...
}
One of the properties added to the Form object is called 'enable', it
is a function so you can use:
Form.enable()
In Firefox and other browsers that allow the basic document elements
to be extended, all form objects in the document are extended with the
same properties as the Prototype Form object so in Firefox you can do:
<form>
<input type="button" onclick="alert(typeof this.form.enable);"
value="click">
</form>
and you will see an alert with "function", but in IE you'll see
'undefined'. So to be cross-browser you must do:
onclick="alert(typeof $(this.form).enable);"
>
> on the other hand, if in the enabe_form_edit() I have
> aform.enable();
>
> then this works fine.
Because the enable property is a reference to a function object, so
you can use the call operator with it.
> Questions:
> - why can't I use "Form" as a singleton?
Form is an object, it is not a function, using the call operator ()
with something other than a function will create a runtime error.
> - why is Prototype.Version available but not Form?
Prototype is declared as a global object, it is assigned a property
called Version (among other things). When Prototype.Version is
evaluated, it returns whatever the value of Version has been set to.
The first couple of lines of Prototype.js:
var Prototype = {
Version: '1.5.1_rc2',
...
}
so any time you like after the script element that loads Prototype.js
you can do alert(Prototype.Version) and you will see
'1.5.1_rc2' (provided javascript is available and enabled).
--
Rob
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---