How can you prototype the Form object?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • phocis@gmail.com

    How can you prototype the Form object?

    Hello, I'm writing a AJAX based content management system for kicks
    (not for money), and I want to create a seemless integration of AJAX
    and html forms.

    Inorder to do this, I need to rewrite alot of the basic javascript
    functionality of objects.

    What I need to do... Is prototype the Form object's submit() function.
    But I cannot figure out how.

    E.G.
    // This...
    var new_string = 'asdf';
    String.prototyp e.new_string_fu nction = function () { alert('this is a
    new string function'); };
    // Yields an alert box whenever
    new_string.new_ string_function ();
    // Is called.

    This method works for:
    Window, Document, Object, and many other things. But not for Form. Why?
    Am I just missing the Form's core class name? What could it be?

    I've looked around for hacked core source codes of JS, but I can't find
    any. So... Does anyone know how to nab this sucker's class name?

    Many thanks,
    Carl

  • Martin Honnen

    #2
    Re: How can you prototype the Form object?



    phocis@gmail.co m wrote:

    [color=blue]
    > Am I just missing the Form's core class name? What could it be?[/color]

    There are no classes in JavaScript 1.x. Inheritance for user defined
    objects is prototype based. There is no requirement for host objects to
    do and expose the same.
    Mozilla in its DOM might expose
    HTMLFormElement .prototype.subm it
    but don't expect that to be cross browser. IE/Win certainly does not
    expose this.

    --

    Martin Honnen

    Comment

    • VK

      #3
      Re: How can you prototype the Form object?


      phocis@gmail.co m wrote:[color=blue]
      > What I need to do... Is prototype the Form object's submit() function.
      > But I cannot figure out how.[/color]

      I guess you may overload Form element in Firefox (I never tried but
      rumors are that it's possible).

      You definitely cannot overload HTML elements in IE from within script.
      The core difference between window / document and form is that both
      window / document are host objects, and form is just uhm... simply
      <form> element. Never was good on theory though.

      You can force HTML elements to act bizarre in IE by attaching behavior
      files to them (.htc)
      In the context of the behavior file the core "element" object is being
      exposed.

      But maybe you would agree on something more easy and universal like:

      function mySubmit() {
      // return either true (submit)
      // or false (don't)
      }

      var frm = document.getEle mentsByTagName( 'FORM');
      for (var i=0; i<frm.length; i++) {
      frm[i].onsubmit = function(){retu rn mySubmit();}
      }

      ?

      Comment

      Working...