Error: Submit is not defined

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J Krugman

    Error: Submit is not defined



    The following line

    document.someFo rm.next = new Submit("next");

    produces the error

    Error: Submit is not defined

    I find this surprising, given that Submit descends from Object,
    and the constructor 'new Object("value") ' is well defined...
    Clearly JavaScript and I have very different ideas about inheritance.

    Be that as it may, is it possible to generate a new HTML input
    element on the fly (i.e. in response to some user action, such as
    a mouse click)?

    Thanks!

    jill
  • Martin Honnen

    #2
    Re: Error: Submit is not defined



    J Krugman wrote:

    [color=blue]
    > Be that as it may, is it possible to generate a new HTML input
    > element on the fly (i.e. in response to some user action, such as
    > a mouse click)?[/color]

    Yes, in browsers that support the W3C DOM you can create an element with
    tagname input with
    var input;
    if (document.creat eElement) {
    input = document.create Element('input' );
    input.type = 'submit';
    input.defaultVa lue = input.value = 'submit form';
    document.forms. formName.append Child(input);
    }

    --

    Martin Honnen


    Comment

    • Michael Winter

      #3
      Re: Error: Submit is not defined

      On Wed, 11 Feb 2004 13:19:46 +0000 (UTC), J Krugman
      <jill_krugman@y ahoo.com> wrote:

      [snip]
      [color=blue]
      > I find this surprising, given that Submit descends from Object,
      > and the constructor 'new Object("value") ' is well defined...
      > Clearly JavaScript and I have very different ideas about inheritance.[/color]

      Actually, Netscape's JavaScript reference (v1.3) defines no parameters for
      the Object constructor. As this is the last specification where the Submit
      object exists, it's probably the most appropriate definition to follow.
      Furthermore, the same specification only provides object creation through
      HTML (i.e. the presence of an INPUT element), not dynamic instantiation.
      [color=blue]
      > Be that as it may, is it possible to generate a new HTML input
      > element on the fly (i.e. in response to some user action, such as
      > a mouse click)?[/color]

      That said, you can certainly use the DOM to create new HTML elements.
      DHTML probably supports it, too.

      var formElement = <reference to form object>;

      if( document.create Element && document.append Child ) {
      var newSubmitButton = document.create Element('input' );

      if( newSubmitButton ) {
      newSubmitButton .type = 'submit';
      newSubmitButton .value = 'Next';

      formElement.app endChild( newSubmitButton );
      }
      }

      This adds a submit button to the end of the form referenced by
      'formElement'. It works in Opera 7.23, Netscape 7, Mozilla 1.6, and IE 6.
      Note that some earlier browsers will not support this.

      Mike

      --
      Michael Winter
      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      • Michael Winter

        #4
        Re: Error: Submit is not defined

        On Wed, 11 Feb 2004 14:52:37 GMT, Michael Winter
        <M.Winter@bluey onder.co.invali d> wrote:

        [snip]
        [color=blue]
        > var formElement = <reference to form object>;
        >
        > if( document.create Element && document.append Child ) {[/color]

        That should probably be

        if( document.create Element && formElement.app endChild ) {

        Mike

        --
        Michael Winter
        M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

        Comment

        • kaeli

          #5
          Re: Error: Submit is not defined

          In article <c0da5i$lph$1@r eader2.panix.co m>, jill_krugman@ya hoo.com
          enlightened us with...[color=blue]
          >
          >
          > The following line
          >
          > document.someFo rm.next = new Submit("next");
          >
          > produces the error
          >
          > Error: Submit is not defined[/color]

          I've never heard of that one...
          A submit object, that is.
          [color=blue]
          >
          > Be that as it may, is it possible to generate a new HTML input
          > element on the fly (i.e. in response to some user action, such as
          > a mouse click)?
          >[/color]

          Look into createElement and appendChild.


          --
          --
          ~kaeli~
          Hey, if you got it flaunt it! If you don't stare at someone
          who does. Just don't lick the TV screen, it leaves streaks.



          Comment

          Working...