Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #12489
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: Referring to Controls by id |
| From | "Evertjan." <exjxw.hannivoort@interxnl.net> |
| References | <191dl7ltuts723trrgoj29mln2b3uvqflk@4ax.com> <4f56ba86$0$2810$a8266bb1@newsreader.readnews.com> <XnsA00F7461D2062eejj99@194.109.133.133> <2g4fl7pjlg8ti787d1nael0mfa7ka92oei@4ax.com> |
| Message-ID | <XnsA0106D358FECFeejj99@194.109.133.133> (permalink) |
| Date | 2012-03-08 09:44 +0000 |
Gene Wirchenko wrote on 07 mrt 2012 in comp.lang.javascript:
> On 07 Mar 2012 10:26:27 GMT, "Evertjan."
> <exjxw.hannivoort@interxnl.net> wrote:
>
>>Denis McMahon wrote on 07 mrt 2012 in comp.lang.javascript:
>>
>>> On Tue, 06 Mar 2012 14:03:52 -0800, Gene Wirchenko wrote:
>>>
>>>> I suppose I will just change everything to use
>>>> document.getElementById(), but the above is shorter.
>>
>>Indeed, using IE-only code is a bad idea.
>>
>>But "everything"?
>
> I think so. A lot of my code operates by fieldname. I have an
> object associated with each control that has properties used with it:
> name, datatype, size, formatting options, validation code, etc.
What is a fieldname [in HTML]?
Do you mean the <td> cells of a <table><tr> row?
There are nice DOM-methods for that: [not tested]
var myTables = document.getElementsByName('myTables');
myTables[2].tBodies[7].rows[31].cells[12].style.color = '#a00';
or:
function getCellContent(table,row,cell) {
var myTables = document.getElementsByName(table);
return myTables[0].rows[row].cells[cell].innerHTML;
};
>>The use of
>>
>>document.forms[].elements[].
>
> I have only seen that with numeric sbuscripts. I have not
> experimented with it.
var anInput = 'thatInput';
var result = document.forms['thisForm'].elements[anInput].value
or
document.forms.thisForm.getElementsByTagName('input').7.checked =
'checked';
>>this.
>>this.form.
>>elementPointer.getElementsBy*()
>
> elementPointer? I have only seen getElement*() under document.
The getElement[s]* can be restricted to the children of an element.
[this is more useful with getElementsBy* than with getElementBy*,
since the unique-id requirement]
<form name='thisForm'>
<button name='thatButton'>
<span>A</span> <span>B</span> <span>C</span><br>
<span>D</span> <span>E</span>
</button>
</form>
var elementPointer = document.forms['thisForm'].elements['thatButton'];
var theseSpans = elementPointer.getElementsByTagName('span');
theseSpans[2].style.fontWeight = 800;
... will only bold the 3th span of that an element named 'thatButton'
in a form named 'thisForm'. [named != id-ed] [not tested]
>>can make live much easier,
>>as more general functions can be written.
>>
>>> You could wrap document.getElementById thus:
>>> function el( id ) { return document.getElementById( id ); }
>>
>>This function is most commonly named gebi()
>
> Already thinking of it.
;-)
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-06 14:03 -0800
Re: Referring to Controls by id Jeff North <jnorthau@yahoo.com.au> - 2012-03-07 09:23 +1100
Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-06 15:02 -0800
Re: Referring to Controls by id Jeff North <jnorthau@yahoo.com.au> - 2012-03-07 19:08 +1100
Re: Referring to Controls by id "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-03-07 10:44 +0200
Re: Referring to Controls by id Jeff North <jnorthau@yahoo.com.au> - 2012-03-07 23:32 +1100
Re: Referring to Controls by id Dr J R Stockton <reply1210@merlyn.demon.co.uk> - 2012-03-07 21:26 +0000
Re: Referring to Controls by id Denis McMahon <denismfmcmahon@gmail.com> - 2012-03-07 01:31 +0000
Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-06 22:33 -0800
Re: Referring to Controls by id Dr J R Stockton <reply1210@merlyn.demon.co.uk> - 2012-03-08 19:06 +0000
Re: Referring to Controls by id "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-07 10:26 +0000
Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-07 08:55 -0800
Re: Referring to Controls by id "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-08 09:44 +0000
Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-08 19:26 -0800
csiph-web