control a form submit


C

cate

I have something like this (trimmed down)

<form id="aform",method="post">
<input type="submit" id="butOne", value="butOne">
<textarea id="tx1"></textarea>
<input type="submit" id="butTwo" value="butTwo">
<textarea id="tx2"></textarea>
</form>

I want to intercept the submit action on butOne, so I tried this

<input type="button" id="butOne", value="butOne" onClick="checkStuff
(this);">

.... and added the js

function checkStuff(e) {
test test test
document.getElementById('aform').submit();
}

Problem is that the two textarea don't seem to post. Go back to
type=submit and everything seems fine.

Thank you.
 
Ad

Advertisements

T

Thomas 'PointedEars' Lahn

cate said:
I have something like this (trimmed down)

<form id="aform",method="post">
<input type="submit" id="butOne", value="butOne">
<textarea id="tx1"></textarea>
<input type="submit" id="butTwo" value="butTwo">
<textarea id="tx2"></textarea>
</form>

Ahh -- yes. Pray learn HTML first.

<http://validator.w3.org/>


PointedEars
 
G

Gregor Kofler

cate meinte:
I have something like this (trimmed down)

<form id="aform",method="post">
<input type="submit" id="butOne", value="butOne">
<textarea id="tx1"></textarea>
<input type="submit" id="butTwo" value="butTwo">
<textarea id="tx2"></textarea>
</form>

Creative markup.
Problem is that the two textarea don't seem to post. Go back to
type=submit and everything seems fine.

Whatever that means...
Thank you.

You are welcome.

Gregor
 
S

Scott Sauyet

I have something like this (trimmed down)

<form id="aform",method="post">
 <input type="submit" id="butOne", value="butOne">
 <textarea id="tx1"></textarea>
 <input type="submit" id="butTwo" value="butTwo">
 <textarea id="tx2"></textarea>
</form>

One thing people want you to notice about the HTML is that you haven't
closed your input tags
I want to intercept the submit action on butOne, so I tried this

 <input type="button" id="butOne", value="butOne" onClick="checkStuff
(this);">

Usually you will want to end the inline handler with "return false;"
If not, your code will run and then the form will be submitted, even
if you would rather it didn't. And the attribute name is
"onclick" (all lower-case);

onclick="checkStuff(this); return false;"

One problem with "type='button'" is that this will not do anything for
users without Javascript or for those with Javascript disabled. You
can do the same thing with "type='submit'" without those problems.
... and added the js

function checkStuff(e) {
  test test test
  document.getElementById('aform').submit();

}

You might also want to consider removing the inline handler, and
running something after the document is loaded to connect a click
handler to the button or a submit handler to the form.

window.onload = function() {
var aForm = document.getElementById("aform");
if (aForm) {
aForm.onsubmit = function() {
var result = runMyTests();
return result;
}
}
}

Good luck,

-- Scott
 
T

Thomas 'PointedEars' Lahn

Scott said:
One thing people want you to notice about the HTML is that you haven't
closed your input tags

Nobody knowing what they are talking about would say such an incredibly
stupid thing. The "input tags" are closed (there's the TAGC delimiter,
`>'). The INPUT elements, if this is HTML, are fine except for the comma;
Usually you will want to end the inline handler with "return false;"

No, usually you would want to cancel the `submit' event of the form
instead. If, and only if, the control would cause form submission by
default, which this one does NOT.
You might also want to consider removing the inline handler, and
running something after the document is loaded to connect a click
handler to the button or a submit handler to the form.

window.onload = function() {

You're really the worst kind of wannabe. Please have the kindness
and be quiet until you got your facts right. Thank you in advance.

OP: Don't listen to Scott.


PointedEars
 
G

Gregor Kofler

Scott Sauyet meinte:
One thing people want you to notice about the HTML is that you haven't
closed your input tags

They won't.
Usually you will want to end the inline handler with "return false;"
If not, your code will run and then the form will be submitted, even
if you would rather it didn't. And the attribute name is
"onclick" (all lower-case);

onclick="checkStuff(this); return false;"

Which won't cancel a submit with button-type input elements.
One problem with "type='button'" is that this will not do anything for
users without Javascript or for those with Javascript disabled. You
can do the same thing with "type='submit'" without those problems.


You might also want to consider removing the inline handler, and
running something after the document is loaded to connect a click
handler to the button or a submit handler to the form.

window.onload = function() {
var aForm = document.getElementById("aform");
if (aForm) {
aForm.onsubmit = function() {
var result = runMyTests();
return result;
}
}
}

There's only a body.onload... Besides I can't see any advantage of this
approach, at least not in this specific case.

Gregor
 
Ad

Advertisements

A

Asen Bozhilov

Scott Sauyet said:
    window.onload = function() {
        var aForm = document.getElementById("aform");
        if (aForm) {
            aForm.onsubmit = function() {
                var result = runMyTests();
                return result;
            }
        }
    }

You make a circular reference pattern.

VO -> aForm -> onsubmit -> AFE[[scope]] -> VO

JScript implementation before version 5.8 have trouble with garbage
collection especially, when deal with host objects.



You should break circular reference:

aForm.onsubmit = function(){
};
aForm = null;

Regards.
 
S

Scott Sauyet

You're really the worst kind of wannabe.  Please have the kindness
and be quiet until you got your facts right.  Thank you in advance.

OP: Don't listen to Scott.

OP: Instead, listen to all the useful advice Thomas has given so far.
Oh wait, all he has offered is non-specific criticism of your markup,
and a partially-valid critique of my suggestions.

-- Scott
 
S

Scott Sauyet

You make a circular reference pattern.

VO -> aForm -> onsubmit -> AFE[[scope]] -> VO
[ ... ]
You should break circular reference:

aForm.onsubmit = function(){};
aForm = null;

Absolutely correct. Thank you for pointing it out.

-- Scott
 
R

Richard Cornford

OP: Instead, listen to all the useful advice Thomas has given
so far. Oh wait, all he has offered is non-specific criticism
of your markup, and a partially-valid critique of my suggestions.

Assuming the above is not part of a "partially-valid critique" of your
suggestions (as it seems to be a general comment rather than being
about any suggestions made), which part of his "critique" was not
valid?

Your comments in relation to the mark-up were absolutely wrong (both
in terms of what 'people' were trying to draw attention towards and
the technical aspects of your suggested changes), and Thomas' comments
on it were spot-on. His comments on the "return false;" suggestions
may have started out with a slightly subjective assertion (if one that
I agree with), but the observation that <input type="button"> elements
don't have a default action to be cancelled by such code was making a
valid point.

I do not agree with the section you quoted above. VK is easily "the
worst kind of wannabe" (combining, as he does, a self-created fantasy
understanding of javascript, an inability to understand when he is
shown to be wrong and an approach to reasoning that rarely achieves
lucidity) (sorry, I could not think of a way of expressing that which
does imply that you are also a "wannabe", which is not sort of
terminology that I would normally use, and strikes me as a very
premature conclusion). And being quiet until you get your facts right
would be a very bad idea, and generally unwelcome. As a learning
exercise, it is best to say what you think about the subject and then
listen to the criticism that receives. And it is in the discussions
that follow from those exchanges that much of the interesting content
on the group can be found.

Richard.
 
S

Scott Sauyet

Assuming the above is not part of a "partially-valid critique" of your
suggestions (as it seems to be a general comment rather than being
about any suggestions made), which part of his "critique" was not
valid?

Your comments in relation to the mark-up were absolutely wrong (both
in terms of what 'people' were trying to draw attention towards and
the technical aspects of your suggested changes), and Thomas' comments
on it were spot-on. His comments on the "return false;" suggestions
may have started out with a slightly subjective assertion (if one that
I agree with), but the observation that <input type="button"> elements
don't have a default action to be cancelled by such code was making a
valid point.

Well, his comments on the mark-up are only valid for HTML doctypes.
Whereas this is valid for HTML4 or XHTML:

<input type="submit" id="butOne" value="butOne"/>

But a major point is that when the OP prefaced the markup with this:

| I have something like this (trimmed down)

criticizing the markup for its failure to include rows/cols attributes
on the textareas or block elements around the form controls or for
some spurious commas in what's typed in to this post seems to be pure
pettiness. It's certainly not aimed at actually helping the OP solve
the problem at hand, as far as I can tell. I guess I should have
realized that it was just that sort of pettiness at play, but I'm not
sure it was a valid critique to assume that Thomas knew the OP's
DOCTYPE, and hence I was wrong. Obviously I did get wrong what others
were criticizing in the markup, though.

Thomas' critique of my suggestion about "return false" were not only
subjective; they also ignored the succeeding paragraph where I
explicitly suggested that the OP not change to type="button", but
stick with type="submit", for which the default action *is* the form
submit we want to cancel.

I do not agree with the section you quoted above. VK is easily "the
worst kind of wannabe" (combining, as he does, a self-created fantasy
understanding of javascript, an inability to understand when he is
shown to be wrong and an approach to reasoning that rarely achieves
lucidity) (sorry, I could not think of a way of expressing that which
does imply that you are also a "wannabe", which is not sort of
terminology that I would normally use, and strikes me as a very
premature conclusion).

Actually, I have pretty thick skin. Maybe I am a wannabe. :)

And being quiet until you get your facts right
would be a very bad idea, and generally unwelcome. As a learning
exercise, it is best to say what you think about the subject and then
listen to the criticism that receives.

Agreed. I'm sure I won't be a member of this forum for years on end,
but while I am here, I plant to learn what I can, and to share what
I've learned. That doesn't involve being quiet, even if I know I'm
likely to be wrong fairly often.

And it is in the discussions
that follow from those exchanges that much of the interesting content
on the group can be found.

Yes, that's true. But I also would prefer that the environs were at
least hospitable to less advanced JS users here earnestly asking for
advice. That was the only reason that I bothered to respond to
Thomas.

I would not have posted my first message on this thread had someone
given the OP a competent answer, preferring to learn from the most
experienced people here. But all that had been posted were small-
minded critiques of the markup. After my response, Asen gave a useful
critique of my post offering an improvement to my suggestion for the
OP, Gregor gave a less useful response that argued against my
suggestions but gave no suggestions for the OP, and Thomas gave one
that criticized my solution, insulted me, and still offered no help to
the OP.

I believe I am not overly sensitive. Had Thomas actually offered
competent help to the OP, I would not have responded to his insults.
But since the only response was, in essence, "Your markup sucks; go
away," I didn't feel Thomas had earned the right to insult my efforts
unchallenged.

I'm curious as to whether someone in this group, had the OP used the
following markup (which I think would be valid in HTML or XHTML),
would have posted a more useful response:

<form id="aform" method="post" action="myAction">
<p>
<input type="submit" id="butOne" value="butOne"/>
<textarea id="tx1" rows="3" cols="20"></textarea>
<input type="submit" id="butTwo" value="butTwo"/>
<textarea id="tx2" rows="3" cols="20"></textarea>
</p>
</form>

Would that have made a difference? Is this newsgroup really that
petty?

-- Scott
 
Ad

Advertisements

D

David Mark

Scott said:
Well, his comments on the mark-up are only valid for HTML doctypes.
Whereas this is valid for HTML4 or XHTML:

<input type="submit" id="butOne" value="butOne"/>

Not a chance. Lose the slash.
But a major point is that when the OP prefaced the markup with this:

| I have something like this (trimmed down)

criticizing the markup for its failure to include rows/cols attributes
on the textareas or block elements around the form controls or for
some spurious commas in what's typed in to this post seems to be pure
pettiness.

How is that your concern? Is there something about extra (and correct)
information that grinds your gears? You write too much about other
people and what they are doing. Try to stick to ideas.
It's certainly not aimed at actually helping the OP solve
the problem at hand, as far as I can tell.

Again, you are not the group constable. Nobody wants to hear you go on
and on (and on and on) about other people's posts. If you have
something to add, add it. Otherwise, leave it alone (or use email to
communicate your suggestions).
I guess I should have
realized that it was just that sort of pettiness at play, but I'm not
sure it was a valid critique to assume that Thomas knew the OP's
DOCTYPE, and hence I was wrong. Obviously I did get wrong what others
were criticizing in the markup, though.

Well, no shock there as you are clearly a beginner. Best to listen more
than you speak at this point on the learning curve. ;)
Thomas' critique of my suggestion about "return false" were not only
subjective; they also ignored the succeeding paragraph where I
explicitly suggested that the OP not change to type="button", but
stick with type="submit", for which the default action *is* the form
submit we want to cancel.

That must have been one of those wrong things mentioned. No you don't
change to a submit button (unless you are submitting a form). And don't
switch to a button element either (in case that one came up too).
Actually, I have pretty thick skin. Maybe I am a wannabe. :)

I don't see the connection. Did you mean wallaby? :)
Agreed. I'm sure I won't be a member of this forum for years on end,
but while I am here, I plant to learn what I can, and to share what
I've learned. That doesn't involve being quiet, even if I know I'm
likely to be wrong fairly often.



Yes, that's true. But I also would prefer that the environs were at
least hospitable to less advanced JS users here earnestly asking for
advice. That was the only reason that I bothered to respond to
Thomas.

That's always the tired refrain of the would-be group cops. In time you
will understand that this is not a help desk, nor could it ever be a
help desk. Help desks cost money for a reason.
I would not have posted my first message on this thread had someone
given the OP a competent answer, preferring to learn from the most
experienced people here. But all that had been posted were small-
minded critiques of the markup.

You never stop. Critics of critics are the worst sort of noise in a
group like this. If you don't like PE's asides, ignore them.
After my response, Asen gave a useful
critique of my post offering an improvement to my suggestion for the
OP, Gregor gave a less useful response that argued against my
suggestions but gave no suggestions for the OP, and Thomas gave one
that criticized my solution, insulted me, and still offered no help to
the OP.

How are you judging all of this? You are a rookie yourself. And if
there are too words I hate here, they are "no help". Tell somebody who
is combining Flash/jQuery/MooTools/YUI/Prototype on one page to stop
doing it as you aren't about to wade through all of that crap and they
start shrieking "no help!", hoping to appeal to group pathos. Yes, they
usually claim to have been insulted too. If it's a moderated group,
calls for bans usually follow. One schnook begets two, two beget four,
etc. Discussion groups are idiot multipliers (or there are a lot of
really smart people just pretending to be morons online).
I believe I am not overly sensitive. Had Thomas actually offered
competent help to the OP, I would not have responded to his insults.

Again, it's not really for you to judge. Relatively speaking, you are
nobody. :(
But since the only response was, in essence, "Your markup sucks; go
away," I didn't feel Thomas had earned the right to insult my efforts
unchallenged.

But that wasn't it, was it?
I'm curious as to whether someone in this group, had the OP used the
following markup (which I think would be valid in HTML or XHTML),
would have posted a more useful response:

<form id="aform" method="post" action="myAction">
<p>
<input type="submit" id="butOne" value="butOne"/>
<textarea id="tx1" rows="3" cols="20"></textarea>
<input type="submit" id="butTwo" value="butTwo"/>
<textarea id="tx2" rows="3" cols="20"></textarea>
</p>
</form>

Would that have made a difference? Is this newsgroup really that
petty?

I have no idea what you are talking about. The above is not valid HTML
and XHTML is dead (at least on the Web). So what's with the funny
slashes? :)
 
T

Thomas 'PointedEars' Lahn

Richard said:
I do not agree with the section you quoted above. VK is easily "the
worst kind of wannabe" (combining, as he does, a self-created fantasy
understanding of javascript, an inability to understand when he is
shown to be wrong and an approach to reasoning that rarely achieves
lucidity) (sorry, I could not think of a way of expressing that which
does imply that you are also a "wannabe", which is not sort of
terminology that I would normally use, and strikes me as a very
premature conclusion). And being quiet until you get your facts right
would be a very bad idea, and generally unwelcome. As a learning
exercise, it is best to say what you think about the subject and then
listen to the criticism that receives. And it is in the discussions
that follow from those exchanges that much of the interesting content
on the group can be found.

ACK. Sloppy wording on my part. What I meant to say is this: I think it
is better for one to refrain from trying to help a newbie if oneself does
not yet have a clue what one is talking about (despite having had the
opportunity to read a considerable amount of clarifying postings before;
that's how I define a wannabe).

The confusion that must follow in the newbie by the contradicting and
naturally often much more "technical" corrections then (or later, when they
find out that what was suggested is not as it works), and the unlearning
required, is much more harmful than no answer at all (should nobody
knowledgable decide to reply), or the correct answer(s) only.

Cf. "If you don't know for sure, say so!", and "If you're going to answer
the question at all, give good value." in
<http://catb.org/~esr/faqs/smart-questions.html#id383614>.


PointedEars
 
D

David Mark

The W3C does not agree with you:

Will you please stop demonstrating your ignorance. Those slashes are
errors and will have to be error-corrected by the browser. The fact
that the online validation tool now calls them "warnings" instead of
errors is irrelevant. It's just a piece of software (and not a
particularly good one either). So don't get caught up in the
semantics of its messages. ;)
 
T

Thomas 'PointedEars' Lahn

Richard said:
That is a true statement (at least to the extent to which it is possible
to declare any mark-up fragment 'valid', given that validity is a
quality that only applies to hole documents in this context), but it is
a true statement behind which there is an explanation that reveals a
very messy truth.

HTML is an application of SGML (Standard Generalised Markup Language, as
defined in ISO 8879). HTML 4 has an "SGML Declaration" which asserts a
set of features from SGML that are (theoretically) used in HTML, and
which impact on HTML validity. An extract from that document reads:-

| <!SGML "ISO 8879:1986 (WWW)"
| --
| SGML Declaration for HyperText Markup Language version HTML 4
| ...
| --
| ...
| FEATURES
| MINIMIZE
| DATATAG NO
| OMITTAG YES
| RANK NO
| SHORTTAG YES
|
| ...

So, for example, that "OMITTAG YES" allows HTML to imply opening and
closing tags based on (structural) context, in a way that is forbidden
in XML (and so in XHTML). The "SHORTTAG YES" makes provision for an SGML
shorthand that allows, e.g.:-

<title></title>

- to be written as:-

<title/

-(note that there is no closing chevron in that TITLE element
declaration).

No SGML markup item (to avoid the ambiguous term "element") is a
declaration if it does not start with `<!' (Markup Declaration Open [MDO]
delimiter).

The correct term for this is _start tag_ (of an element).


PointedEars
 
Ad

Advertisements

T

Thomas 'PointedEars' Lahn

David said:
http://validator.w3.org/check?uri=http://scott.sauyet.com/Javascript/...

Will you please stop demonstrating your ignorance.
ACK.

Those slashes are errors

Not necessarily.
and will have to be error-corrected by the browser.

Yes, most likely, since so far only three implementations have been shown
to implement some features of HTML SHORTTAG:

The fact that the online validation tool now calls them "warnings"
instead of errors is irrelevant.

No, warnings point out that the marked part is actually Valid markup,
however one unwise to use (as in SHOULD NOT). If there is a real error (as
in MUST NOT), it will be flagged as such, regardless whether it is caused
by wrong application of SHORTTAG syntax (like Richard's example for the
SHORTTAGged TITLE element, which, according to my understanding and tests,
can never become Valid).
It's just a piece of software (and not a particularly good one either).

How so? IBTD.

IMNSHO, it is only that many people fail to understand that the W3C
Validator is naturally only a *syntax* validator. As a result, Validation
is in itself not a means to ensure software quality; whether source code
makes sense or not, whether markup is properly used (semantics), and how
compatible it is in a given context (pragmatics), cannot be determined (at
the moment).

However, (IMHO considerable) efforts have been made to improve the
Validator over the years, including to make the Validator's messages more
understable so as to mitigate the inherent disadvantage of a syntax-only
validator, and those efforts should gain some recognition.
So don't get caught up in the semantics of its messages. ;)

In my experience, one (especially newcomers) SHOULD always enable Verbose
Output (checked checkbox, or `verbose=1' as component of the query part
should one want to use tools like Web Developer Toolbar) and try to
understand the explanations given with each warning or error message then.
If still not understandable, maybe the FAQ (explicitly linked to in Verbose
Mode) can provide insight. If not, that is likely to be a case for
checking the TODO list and the bug list, and reporting a bug if no similar
entry can be found in either (regardless whether the report turns out to
show a real bug as in a misrecognition or as in not understandable output,
or no bug at all).

In addition, the W3C Validator is Open Source (under the Open Source
Initiative's Open Source Definition) and free software (GPL-compatible), so
besides reporting bugs there is the possibility for everyone to contribute
in other ways as well or release one's own, perhaps better, fork of the
Validator (follow the "Contribute" link for details).


PointedEars
 
E

Eric Bednarz

Thomas 'PointedEars' Lahn said:
Richard Cornford wrote:
[…] The "SHORTTAG YES" makes provision for an SGML
shorthand that allows, e.g.:-

<title></title>

- to be written as:-

<title/

Not exactly. Rather as:

<title//
No SGML markup item (to avoid the ambiguous term "element") is a
declaration if it does not start with `<!'

That is a false – generalized – statement, because it implies the
reference concrete syntax.
(Markup Declaration Open [MDO]
delimiter).
The correct term for this is _start tag_ (of an element).

The correct term is ‘start-tag’.
 
T

Thomas 'PointedEars' Lahn

Eric said:
Thomas 'PointedEars' Lahn said:
Richard said:
<title/ [...]
-(note that there is no closing chevron in that TITLE element
declaration).

No SGML markup item (to avoid the ambiguous term "element") is a
declaration if it does not start with `<!'

That is a false – generalized – statement, because it implies the
reference concrete syntax.

Maybe so; however, the code above is certainly no declaration.

What other declarations are there in SGML that do not start with `<!'
(MDO)?
(Markup Declaration Open [MDO]
delimiter).
The correct term for this is _start tag_ (of an element).

The correct term is ‘start-tag’.

I daresay that is a matter of preference; the hyphenization of compound
words is not fixed in English. We can find occurrences of "start-tag", but
also "start tag" in references; in the SGML grammar we can also find
"start_tag" which would indicate that the original wording was "start tag"
(as in "element_content" for "element content").


PointedEars
 
Ad

Advertisements

E

Eric Bednarz

Thomas 'PointedEars' Lahn said:
Eric said:
That is a false – generalized – statement, because it implies the
reference concrete syntax.
[…]

What other declarations are there in SGML that do not start with `<!'
(MDO)?

I don’t know what was difficult to understand about my statement.


<!SGML "ISO 8879:1986 (WWW)"
CHARSET
BASESET
"ISO 646:1983//CHARSET International
Reference Version (IRV)//ESC 2/5 4/0"
DESCSET
0 9 UNUSED
9 2 9
11 2 UNUSED
13 1 13
14 18 UNUSED
32 95 32
127 1 UNUSED
CAPACITY
PUBLIC "ISO 8879-1986//CAPACITY Reference//EN"
SCOPE
DOCUMENT
SYNTAX
SHUNCHAR NONE
BASESET
"ISO 646-1983//CHARSET International
Reference Version (IRV)//ESC 2/5 4/0"
DESCSET
0 128 0
FUNCTION
RE 13
RS 10
SPACE 32
TAB SEPCHAR 9
NAMING
LCNMSTRT ""
UCNMSTRT ""
LCNMCHAR ""
UCNMCHAR ""
NAMECASE
GENERAL YES
ENTITY NO
DELIM
GENERAL SGMLREF
DSC "."
DSO ":"
MDC "."
MDO "AN"
NESTC "('"
NET "');"
STAGO "j"
SHORTREF SGMLREF
NAMES
SGMLREF
ANY ANSWERED
DOCTYPE SWER
ELEMENT Y
QUANTITY
SGMLREF
FEATURES
MINIMIZE
DATATAG NO
OMITTAG NO
RANK NO
SHORTTAG YES
LINK
SIMPLE NO
IMPLICIT NO
EXPLICIT NO
OTHER
CONCUR NO
SUBDOC NO
FORMAL NO
APPINFO NONE
Answer query:
Any query answered...
jQuery('SGML is bad, mkay');
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top