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

form element name creates problem

P: n/a
TJS
how can I reference an element name if it has a colon in it ?

example that creates error :
===========================
objForm._ctl1:password.required = 1;
Jul 23 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
On Sun, 19 Sep 2004 11:04:05 -0700, TJS <no****@here.com> wrote:
how can I reference an element name if it has a colon in it ?


Please read the FAQ.

<URL:http://jibbering.com/faq/>

Good luck,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

P: n/a
TJS
thanks that works ...

can you help me with the quotes in the eval too?

code
===========
eval(" 'objForm.elements.[\'' + FullElemName + '\'].required = 1' ");

Error: missing ; before statement
==============================
Line: 40, Column: 22
Source Code:

'objForm.elements.[' ' + FullElemName + ''].required = 1'


"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opsek56ndrx13kvk@atlantis...
On Sun, 19 Sep 2004 11:04:05 -0700, TJS <no****@here.com> wrote:
how can I reference an element name if it has a colon in it ?


Please read the FAQ.

<URL:http://jibbering.com/faq/>

Good luck,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Jul 23 '05 #3

P: n/a
On Sun, 19 Sep 2004 11:37:25 -0700, TJS <no****@here.com> wrote:
can you help me with the quotes in the eval too?
What eval? The code the FAQ suggests doesn't need one. I suggest you read
4.40 and 4.39, too.
eval(" 'objForm.elements.[\'' + FullElemName + '\'].required = 1' ");


Using your original example:

objForm.elements['_ctll:password'].required = 1;

Note the position of the periods.

If required is a boolean, use boolean values:

objForm.elements['_ctll:password'].required = true;

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4

P: n/a
TJS wrote:
thanks that works ...

can you help me with the quotes in the eval too?
The best advice you will get with respect to that code is, read the FAQ,
with regards to eval. You don't need it there.
code
===========
eval(" 'objForm.elements.[\'' + FullElemName + '\'].required = 1' ");
objForm.elements[FullElemName].required = 1;

Appears to be what you are after.

If its not, then explain what you are after.

Error: missing ; before statement
==============================
Line: 40, Column: 22
Source Code:

'objForm.elements.[' ' + FullElemName + ''].required = 1'


Looks like an IE error message, which are generally useless.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5

P: n/a
TJS
i need it to be dynamic

this worked

eval("objForm.elements[\'" + FullElemName + "\'].required = 1");

thanks for replying
"Randy Webb" <Hi************@aol.com> wrote in message
news:wd********************@comcast.com...
TJS wrote:
thanks that works ...

can you help me with the quotes in the eval too?


The best advice you will get with respect to that code is, read the FAQ,
with regards to eval. You don't need it there.
code
===========
eval(" 'objForm.elements.[\'' + FullElemName + '\'].required = 1' ");


objForm.elements[FullElemName].required = 1;

Appears to be what you are after.

If its not, then explain what you are after.

Error: missing ; before statement
==============================
Line: 40, Column: 22
Source Code:

'objForm.elements.[' ' + FullElemName + ''].required = 1'


Looks like an IE error message, which are generally useless.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #6

P: n/a
TJS wrote:
i need it to be dynamic

this worked

eval("objForm.elements[\'" + FullElemName + "\'].required = 1");

thanks for replying


The code I gave is dynamic as well.

Assuming objForm is a reference to the form, and that FullElemName is a
variable containing the name of an element:

objForm.elements[FullElemName].required=1;

But with the way you have it written, it appears to be giving this instead:

objForm.elements['FullElemName'].required=1;

which is not dynamic and I doubt its what you are after.

And please read the FAQ, in its entirety. It covers both questions you
have asked, and it also covers top-posting which is frowned upon in this
particular group.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #7

P: n/a
TJS
I saw FAQ 4.13 which showed using quotes so I tried to follow example.
The eval formula shown produced the actual name inside qoutes and it did
work.

But, the short version works too , so I will use that.

( I hate bottom posting )

cheers


"Randy Webb" <Hi************@aol.com> wrote in message
news:mL********************@comcast.com...
TJS wrote:
i need it to be dynamic

this worked

eval("objForm.elements[\'" + FullElemName + "\'].required = 1");

thanks for replying
The code I gave is dynamic as well.

Assuming objForm is a reference to the form, and that FullElemName is a
variable containing the name of an element:

objForm.elements[FullElemName].required=1;

But with the way you have it written, it appears to be giving this

instead:
objForm.elements['FullElemName'].required=1;

which is not dynamic and I doubt its what you are after.

And please read the FAQ, in its entirety. It covers both questions you
have asked, and it also covers top-posting which is frowned upon in this
particular group.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #8

P: n/a
On Sun, 19 Sep 2004 14:52:38 -0700, TJS wrote:

(Randy Webb)
And please read the FAQ, in its entirety. It covers both questions you
have asked, and it also covers top-posting which is frowned upon in this
particular group.
( I hate bottom posting )


Who said anything about bottom-posting (before you)?
It is not mentioned if the FAQ, nor Randy's post.

Try 'in-line with trimming'..
<http://www.physci.org/codes/javafaq.jsp#netiquette>

Note that the text of the JS FAQ equates to the same
thing, something you might notice, if you read it..

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #9

P: n/a
TJS wrote:
I saw FAQ 4.13 which showed using quotes so I tried to follow example.
http://jibbering.com/faq/#FAQ4_25 is a better place to look than 4.13
The eval formula shown produced the actual name inside qoutes and it did
work.
http://jibbering.com/faq/#FAQ4_40

Deals with the use of eval.
But, the short version works too , so I will use that.

( I hate bottom posting )


It destroys the following of the conversation.
Why?
Top-posting.
Whats the worst thing on Usenet?


--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #10

P: n/a
On Sun, 19 Sep 2004 14:52:38 -0700, TJS <no****@here.com> wrote:
I saw FAQ 4.13 which showed using quotes so I tried to follow example.
The eval formula shown produced the actual name inside qoutes and it did
work.
However, 4.13 doesn't use eval. If you needed to build a property name,
use string concatenation:

document.forms['my' + 'Form']
But, the short version works too , so I will use that.
The "short" version, as you call it, is the much preferred approach. It is
almost *never* necessary to use eval(). Ever.

Code that uses eval is usually slower and it can be harder to debug. Worse
still, it is frequently used as a hack because it seems to get things
working, when in reality it does nothing but burden the browser.
( I hate bottom posting )


Then you might want to learn to like it. It's an established practice,
especially amongst technical newsgroups. Some will even refuse to respond
to you if you continue to top-post after being told to stop. Bear that in
mind.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #11

P: n/a
On Sun, 19 Sep 2004 22:11:59 GMT, Michael Winter wrote:

(TJS)
( I hate bottom posting )
Then you might want to learn to like it. ..


Interestingly, I would not refer to your own
posting style as 'bottom-posting', because...
[snip]


...this suggests to me that your posting style is more
accurately described as 'in-line with trimming'.

[ 'bottom-posting' is actually something I advise
against in my (Java) FAQ, and the text of the JS FAQ
does not contain the word 'bottom'. It might seem
like an trivial difference, but I have become sick
of reading posts from people who add 1 line at the
bottom of a 140 line post! ]

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #12

P: n/a
On Sun, 19 Sep 2004 22:39:21 GMT, Andrew Thompson <Se********@www.invalid>
wrote:

[snip]
Interestingly, I would not refer to your own
posting style as 'bottom-posting', because...
[snip]
..this suggests to me that your posting style is more
accurately described as 'in-line with trimming'.


It is, but it is my understanding that the style is simply referred to as
bottom-posting. However, if I were to describe to someone how to correctly
post on Usenet, I would say (and have said):

When posting, please write in conversation order; place your
response beneath the text it addresses. Remaining quoted text
which you are not answering should be trimmed. Signatures should
always be removed unless they are being discussed.

I'm usually more terse than that, though.
[ 'bottom-posting' is actually something I advise
against in my (Java) FAQ, and the text of the JS FAQ
does not contain the word 'bottom'.
To truly bottom-post is just as illogical as top-posting. Neither style
allows a reader to tell what parts of a poster's response refers to which
of the preceeding points (did that make sense?).
It might seem like an trivial difference, but I
have become sick of reading posts from people who
add 1 line at the bottom of a 140 line post! ]


I know what you mean. :|

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #13

P: n/a
JRS: In article <10*************@corp.supernews.com>, dated Sun, 19 Sep
2004 14:52:38, seen in news:comp.lang.javascript, TJS <no****@here.com>
posted :
I saw FAQ 4.13 which showed using quotes so I tried to follow example.
The eval formula shown produced the actual name inside qoutes and it did
work.

But, the short version works too , so I will use that.

( I hate bottom posting )

Since the regulars prefer to comply with recognised Usenet standards,
ISTM likely that they will in future not bother to reply to you. You'll
still get replies, but mainly from the ignorant.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.