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

Submit in Javascript?

P: n/a
Hi All,

I am really green at Javascript. Someone gave me some code to play
with and I'm trying to understand it:

<INPUT TYPE=text NAME=subject SIZE=60 MAXLENGTH=60><BR><BR>
<input type='submit' name='Duplicate' VALUE='Duplicate'
onclick="validate.submit = this;">

What is the purpose of "submit"? I think that 'validate' is the same
of the function. Also, what is 'this'? It referring to 'this' passing
the entire form?

Here is a copy of the function:

<script type="text/javascript">
function validate(f) {
if (f && arguments.callee.submit.name != "Duplicate") {
// perform validation, return `false' if the result is negative
document.write(arguments.callee.subject);
document.write(arguments.callee.submit.name);
}
return true;
}
validate.submit = {};
</script>

Why is the document.write for subject not working? How can I refer to
fields on the form? It keep printing 'undefined'. Once I get this
working, I can add more of the proper code.......

Thanks for your help......this is just very difficult for me.

Arthur

Jan 19 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
am****@iwc.net wrote:
I am really green at Javascript. Someone gave me some code to play
with and I'm trying to understand it:
You have e-mail as a reply to yours (since about 7 hours ago at the time I
am posting this). Please read it thoroughly before you post a followup to
this posting.
<INPUT TYPE=text NAME=subject SIZE=60 MAXLENGTH=60><BR><BR>
`TYPE=text' is redundant as that is the default attribute value, and all
attribute values SHOULD be delimited by single (') or double (") quotes.
See the HTML 4.01 Specification for details.
<input type='submit' name='Duplicate' VALUE='Duplicate'
onclick="validate.submit = this;">

What is the purpose of "submit"?
I think that 'validate' is the same of the function.
Also, what is 'this'?
The Function object referred to by `validate' is added a new property,
its value being a reference to the element object representing the
activated `input' (here: submit button) element.
It referring to 'this' passing the entire form?
In intrinsic event handler attribute values, `this' refers to the DOM
element object representing the element that fired the event. Therefore,
`this' in the `onsubmit' handler attribute value of the `form' element
refers to the HTMLFormElement object that represents that `form' element.
Here is a copy of the function:

<script type="text/javascript">
function validate(f) {
if (f && arguments.callee.submit.name != "Duplicate") {
// perform validation, return `false' if the result is negative
document.write(arguments.callee.subject);
document.write(arguments.callee.submit.name);
}
return true;
}
validate.submit = {};
</script>

Why is the document.write for subject not working?
"Does not work" is a useless error description. [psf 4.11]

<URL:http://jibbering.com/faq/#FAQ4_43>
How can I refer to fields on the form?
f.elements['subject'], for example.
It keep printing 'undefined'.
Fortunately, my crystal ball is quite clear tonight, so I can see that in
your browser is displayed `undefined' where you expected the value of a
form control named `subject' (it is not as clear as I thought, though :))

However, this cannot be. `arguments.callee' refers to the called function,
that is the `validate' Function object, which does not have a `subject'
property. Furthermore, calling document.write() there is very likely to
_overwrite_ the document the code is located in.
Thanks for your help......this is just very difficult for me.


RTFFAQ, RTFM.
HTH

PointedEars
Jan 20 '06 #2

P: n/a
Thomas 'PointedEars' Lahn said the following on 1/19/2006 8:41 PM:
am****@iwc.net wrote:
I am really green at Javascript. Someone gave me some code to play
with and I'm trying to understand it:
You have e-mail as a reply to yours (since about 7 hours ago at the time I
am posting this). Please read it thoroughly before you post a followup to
this posting.


You are assuming that if you send an email that it actually gets
delivered, and read, by the person you wanted to read it. And spare all
of us the useless drivel about mailboxes. Its irrelevant and gets old
after you read it about 18 times.

But based on this post, I can see why you would want to email it and not
have it open to public scrutiny.
<INPUT TYPE=text NAME=subject SIZE=60 MAXLENGTH=60><BR><BR>


`TYPE=text' is redundant as that is the default attribute value, and all
attribute values SHOULD be delimited by single (') or double (") quotes.
See the HTML 4.01 Specification for details.


Such as you do on your own website?
<input type='submit' name='Duplicate' VALUE='Duplicate'
onclick="validate.submit = this;">

What is the purpose of "submit"?
I think that 'validate' is the same of the function.
Also, what is 'this'?


The Function object referred to by `validate' is added a new property,
its value being a reference to the element object representing the
activated `input' (here: submit button) element.


But only if validate is a fully qualified reference to the Form.
Otherwise it is an IE only practice.

It referring to 'this' passing the entire form?


In intrinsic event handler attribute values, `this' refers to the DOM
element object representing the element that fired the event. Therefore,
`this' in the `onsubmit' handler attribute value of the `form' element
refers to the HTMLFormElement object that represents that `form' element.
Here is a copy of the function:

<script type="text/javascript">
function validate(f) {
if (f && arguments.callee.submit.name != "Duplicate") {
// perform validation, return `false' if the result is negative
document.write(arguments.callee.subject);
document.write(arguments.callee.submit.name);
}
return true;
}
validate.submit = {};
</script>

Why is the document.write for subject not working?


"Does not work" is a useless error description. [psf 4.11]


He did not say "Does not work". He asked why the document.write was not
working. And typically when document.write "doesn't work" then it
indicates that there is nothing written, or, it is not what is expected.
<URL:http://jibbering.com/faq/#FAQ4_43>
How can I refer to fields on the form?
f.elements['subject'], for example.


IFF f points to the form element.

RTFFAQ, RTFM.


If you would do that, then maybe your own personal website wouldn't have
so many problems with it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 20 '06 #3

P: n/a
Randy Webb <Hi************@aol.com> writes:
Thomas 'PointedEars' Lahn said the following on 1/19/2006 8:41 PM:

`TYPE=text' is redundant as that is the default attribute value, and
all
attribute values SHOULD be delimited by single (') or double (")
quotes. See the HTML 4.01 Specification for details.


Such as you do on your own website?


His own website is irrelevant to his advice. It is good advice, and
should be followed when writing web pages. Incorrect HTML can, and do,
cause or affect errors in scripting that makes debugging much harder
(and can cause even bigger problems for CSS that may be attributed to
the script). This is why it is generally recommended to make the HTML
valid before trying to fix scripting errors.

Often the scripting errors are not related to the HTML errors,
and the script can be debugged anyway. It's just that the one
case where it is related will take so much more time to debug
that it is prudent to ask the author to do the relatively minor
job of fixing HTML problems before trying to debug the page.

It simply helps everybody fix the real problem sooner.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jan 20 '06 #4

P: n/a
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 1/19/2006 8:41 PM:
am****@iwc.net wrote:
I am really green at Javascript. Someone gave me some code to play
with and I'm trying to understand it:


You have e-mail as a reply to yours (since about 7 hours ago at the time ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I am posting this). Please read it thoroughly before you post a followup
to this posting.


You are assuming that if you send an email that it actually gets
delivered, and read, by the person you wanted to read it.


<Q>You obtuse piece of flotsam!</Q>[1] Arthur asked me privately via e-mail
about _my code_ before and I replied to him privately via e-mail. The
above was just a suggestion that he should read that e-mail first as it
already clears up many of his further questions.

But then, kind one-to-one communication like private e-mail correspondence
between posters caused by kind actions in a one-to-many medium like NetNews
must seem like an impossible thing to an incompetent troll as you obviously
are, so I do not really blame you for not knowing.

Why don't you just get a life?
PointedEars
___________
[1] That's "Q" in both senses <g/>
Jan 20 '06 #5

P: n/a
Lasse Reichstein Nielsen said the following on 1/20/2006 2:08 PM:
Randy Webb <Hi************@aol.com> writes:
Thomas 'PointedEars' Lahn said the following on 1/19/2006 8:41 PM:
`TYPE=text' is redundant as that is the default attribute value, and
all
attribute values SHOULD be delimited by single (') or double (")
quotes. See the HTML 4.01 Specification for details.

Such as you do on your own website?


His own website is irrelevant to his advice.


We have a difference of opinion with that then. It is the "Do as I say,
not as I do" mentality. To me, it is akin to Richard Nixon giving a
lecture on "Ethics in Government" or Bill Clinton giving one on "How to
be Faithful to your spouse".

It's Hypocritical at the least.
It is good advice, and should be followed when writing web pages.


Too much Jim Ley reading makes me disagree with that also. But it's for
another thread/place. Let's just say I am not a big fan of the validator
and leave it at that.

But that is a minor part of the problem. A major part of it is the
tendency in this group, as a whole, to point out things that simply are
irrelevant. Someone could post 40 lines of some of the most horrific
HTML code and ask why
document.forms['formName'].elements['elementID'].value works in IE but
not in Firefox and you will get an 800 line dissertation on the HTML/CSS
and one short line about what the problem is.

If there is a problem with the HTML itself, refer them to ciwah.
If there is a problem with the CSS, refer them to ciwas.

I have always thought it odd that the validity of CSS and HTML isn't in
the FAQ though. Is it in the notes? I do not find the word "valid" in
either.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Jan 22 '06 #6

P: n/a
Thomas 'PointedEars' Lahn typed and posted the following to
news:comp.lang.javascript on January 20th in the year 2006 of the
proleptic Gregorian Calendar in response to an article posted in the
same newsgroup also on January 20th in the year 2006 of the proleptice
Gregorian Calender whereby he thought he was posting to
de.comp.lang.javascript where the regulars (if there are any besides
him) have a fear of him and fear being called a troll when he gets
corrected:
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 1/19/2006 8:41 PM:
am****@iwc.net wrote:
I am really green at Javascript. Someone gave me some code to play
with and I'm trying to understand it:
You have e-mail as a reply to yours (since about 7 hours ago at the time ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I am posting this). Please read it thoroughly before you post a followup
to this posting.

You are assuming that if you send an email that it actually gets
delivered, and read, by the person you wanted to read it.


<Q>You obtuse piece of flotsam!</Q>[1]


I can add that to my list of names I have been called by you. And it
doesn't surprise me. When you get corrected, or have your hypocritical
behavior pointed out, that is your response.

<snipped irrelevant ramblings>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 22 '06 #7

P: n/a
Randy Webb <Hi************@aol.com> writes:
Lasse Reichstein Nielsen said the following on 1/20/2006 2:08 PM:
His own website is irrelevant to his advice.


We have a difference of opinion with that then. It is the "Do as I
say, not as I do" mentality. To me, it is akin to Richard Nixon giving
a lecture on "Ethics in Government" or Bill Clinton giving one on "How
to be Faithful to your spouse".

It's Hypocritical at the least.


That might or might not be the case, but that's still only relevant to
the poster's person, not to the validity of his advice, which can
stand, or fall, on its own.
But that is a minor part of the problem. A major part of it is the
tendency in this group, as a whole, to point out things that simply
are irrelevant.


I agree that it can become too much, and I try only to comment on the
parts related to the Javascript (including the script tag). I'm as
prone to being overly "helpful" as the next guy at times, though :)

However, I also think a significant problem with this group is the
amount of personal attacks. I really don't care how idiotic,
hypocritical or ignorant someone thinks someone else is. Seeing it
pointed out will not change my opinion of the person being attacked,
since I'm quite capable of forming my own opinion, but it *will* lower
my opinion of the attacker. It is pure noise, and all it does is to
nurture an environment where personal attacks are accepted.

Go for the ball, not the man. The rest of us don't care about the man.
Don't write to whoever you don't like, write to the rest of the
readers to make sure they get a correct answer - you would probably
think they are more worthy of your time and energy anyway.
There is a world between "what you say is incorrect" and "you are an
ignorant" - the former is critique, the latter is an insult.
D on't answer in a way you wouldn't to your mother.
Etc...

/L 'Never argue with idiots. They merely drag you down to their level,
then beat you with experience'
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jan 22 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.