By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,968 Members | 1,458 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,968 IT Pros & Developers. It's quick & easy.

Error: Submit is not defined

P: n/a


The following line

document.someForm.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
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


J Krugman wrote:

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)?


Yes, in browsers that support the W3C DOM you can create an element with
tagname input with
var input;
if (document.createElement) {
input = document.createElement('input');
input.type = 'submit';
input.defaultValue = input.value = 'submit form';
document.forms.formName.appendChild(input);
}

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
On Wed, 11 Feb 2004 13:19:46 +0000 (UTC), J Krugman
<ji**********@yahoo.com> wrote:

[snip]
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.
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.
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)?


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.createElement && document.appendChild ) {
var newSubmitButton = document.createElement('input');

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

formElement.appendChild( 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.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3

P: n/a
On Wed, 11 Feb 2004 14:52:37 GMT, Michael Winter
<M.******@blueyonder.co.invalid> wrote:

[snip]
var formElement = <reference to form object>;

if( document.createElement && document.appendChild ) {


That should probably be

if( document.createElement && formElement.appendChild ) {

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4

P: n/a
In article <c0**********@reader2.panix.com>, ji**********@yahoo.com
enlightened us with...


The following line

document.someForm.next = new Submit("next");

produces the error

Error: Submit is not defined
I've never heard of that one...
A submit object, that is.

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)?


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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.