473,569 Members | 2,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

part of a FORM inside DIV block

i have a block of html code looking like this

<FORM name=myform>
<INPUT type=text name=firstname>
<DIV id=mydiv>
<INPUT type=text name=address>
</DIV>
</FORM>

i can access firstname field with document.myform .firstname

but how to reference to address field which is inside a DIV block.
nor document.myform .mydiv.address neither
document.myform .mydiv.document .address works

any ideas? this is realy kickin' my ass.
Jul 20 '05 #1
18 7234
Michal Mieszkowski hu kiteb:
i have a block of html code looking like this

<FORM name=myform>
<INPUT type=text name=firstname>
<DIV id=mydiv>
<INPUT type=text name=address>
</DIV>
</FORM>

i can access firstname field with document.myform .firstname

but how to reference to address field which is inside a DIV block.
nor document.myform .mydiv.address neither
document.myform .mydiv.document .address works


Have you tried document.myform .address yet?
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #2
ju****@interia. pl (Michal Mieszkowski) writes:
<FORM name=myform>
<INPUT type=text name=firstname>
<DIV id=mydiv>
<INPUT type=text name=address>
</DIV>
</FORM> but how to reference to address field which is inside a DIV block.
nor document.myform .mydiv.address neither
document.myform .mydiv.document .address works


That's not how addressing works. In fact, "document.myfor m" itself
isn't part of any standard.

The appropriate and standards[1] sanctioned way to access a form
control is:
document.forms['myform'].elements['address']
The div is irrelevant to the relation between form and form control.

And it is recommended to use "id" instead of "name" on the form.

/L
[1] Well, at leaset "W3C Recommendation" sanctioned.
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
@SM
Lasse Reichstein Nielsen a ecrit :
And it is recommended to use "id" instead of "name" on the form.


Yes !
But ...
my NC4.5 can't use it !

so :
document.forms[0].elements[2].value
would work everywhere

--
*************** *************** *************** *************** **
Stéphane MORIAUX : mailto:st****** *************** @wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
*************** *************** *************** *************** **
Jul 20 '05 #4
DU
Lasse Reichstein Nielsen wrote:
ju****@interia. pl (Michal Mieszkowski) writes:

<FORM name=myform>
<INPUT type=text name=firstname>
<DIV id=mydiv>
<INPUT type=text name=address>
</DIV>
</FORM>
but how to reference to address field which is inside a DIV block.
nor document.myform .mydiv.address neither
document.myfo rm.mydiv.docume nt.address works

That's not how addressing works. In fact, "document.myfor m" itself
isn't part of any standard.


HTMLCollection can make use of the namedItem method to retrieve a node.

The appropriate and standards[1] sanctioned way to access a form
control is:
document.forms['myform'].elements['address']
document.forms[0].elements.named Item("address")

is perfectly standard and works without a glitch in Mozilla 1.5, Opera
7.23, MSIE 6 for windows and K-meleon 0.8.

DU
The div is irrelevant to the relation between form and form control.

And it is recommended to use "id" instead of "name" on the form.

/L
[1] Well, at leaset "W3C Recommendation" sanctioned.


Jul 20 '05 #5
DU <dr*******@hotW IPETHISmail.com > writes:
Lasse Reichstein Nielsen wrote: HTMLCollection can make use of the namedItem method to retrieve a node.


Yes, or normal property access, using the NAME of the collection element
is the property name.
The appropriate and standards[1] sanctioned way to access a form
control is:
document.forms['myform'].elements['address']


document.forms[0].elements.named Item("address")

is perfectly standard and works without a glitch in Mozilla 1.5, Opera
7.23, MSIE 6 for windows and K-meleon 0.8.


So is and does
document.forms['myform'].elements['address']
(ok, I haven't checked K-meleon, but it's Gecko-based)

Using forms[0] avoids the problem that Netscape 4 apparently has (not
recognizing the id attribute on forms). However, it makes the script
more fragile, since adding a form before the first will break the script.
I would rather put both the "id" and "name" attribute there (with the
same value).

"HTMLcollection " is defined in W3C DOM 2 HTML. The ECMAScript bindings
part of DOM 2 HTML says that using square bracket property access
notation is equivalent to using the namedItem method. Quote:
---
namedItem(name)
This function returns an object that implements the Node interface.
The name parameter is a String.
Note: This object can also be dereferenced using square bracket
notation (e.g. obj["foo"]). Dereferencing using a string index is
equivalent to invoking the namedItem function with that index.
---
(from <URL:http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>)

Since ECMAScript says that obj.foo is equivalent to obj["foo"] when
foo is valid identifier, using the dot notation for property access
should work as well.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6
DU
Lasse Reichstein Nielsen wrote:
DU <dr*******@hotW IPETHISmail.com > writes:

Lasse Reichstein Nielsen wrote:
HTMLCollectio n can make use of the namedItem method to retrieve a node.

Yes, or normal property access, using the NAME of the collection element
is the property name.

The appropriate and standards[1] sanctioned way to access a form
control is:
document.forms['myform'].elements['address']


document.form s[0].elements.named Item("address")

is perfectly standard and works without a glitch in Mozilla 1.5, Opera
7.23, MSIE 6 for windows and K-meleon 0.8.

So is and does
document.forms['myform'].elements['address']
(ok, I haven't checked K-meleon, but it's Gecko-based)


We understand each other. All I wanted to say is that there is just one
appropriate way conforming to W3C web standards to access that node and
its value.
Using forms[0] avoids the problem that Netscape 4 apparently has (not
I really don't care about NS 4. People should stop using such bad browser.
recognizing the id attribute on forms). However, it makes the script
more fragile, since adding a form before the first will break the script.
Then you adjust accordingly. Simple as changing [0] to [1]. Ordinal
index is one way.

DU
I would rather put both the "id" and "name" attribute there (with the
same value).

"HTMLcollection " is defined in W3C DOM 2 HTML. The ECMAScript bindings
part of DOM 2 HTML says that using square bracket property access
notation is equivalent to using the namedItem method. Quote:
---
namedItem(name)
This function returns an object that implements the Node interface.
The name parameter is a String.
Note: This object can also be dereferenced using square bracket
notation (e.g. obj["foo"]). Dereferencing using a string index is
equivalent to invoking the namedItem function with that index.
---
(from <URL:http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>)

Since ECMAScript says that obj.foo is equivalent to obj["foo"] when
foo is valid identifier, using the dot notation for property access
should work as well.

/L


Jul 20 '05 #7
@SM
DU a ecrit :
document.forms[0].elements.named Item("address")

is perfectly standard and works without a glitch in Mozilla 1.5, Opera
7.23, MSIE 6 for windows and K-meleon 0.8.


And so on NN4.5 ??

Don't believe old navigators still running.
--
*************** *************** *************** *************** **
Stéphane MORIAUX : mailto:st****** *************** @wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
*************** *************** *************** *************** **
Jul 20 '05 #8
DU wrote:
Lasse Reichstein Nielsen wrote:
DU <dr*******@hotW IPETHISmail.com > writes:
Lasse Reichstein Nielsen wrote:
The appropriate and standards[1] sanctioned way to access a form
control is:
document.forms['myform'].elements['address']

document.forms[0].elements.named Item("address")

is perfectly standard and works without a glitch in Mozilla 1.5, Opera
7.23, MSIE 6 for windows and K-meleon 0.8.
So is and does
document.forms['myform'].elements['address']
(ok, I haven't checked K-meleon, but it's Gecko-based)


We understand each other.


I am afraid you did not understand.
All I wanted to say is that there is just one appropriate way
conforming to W3C web standards to access that node and its value.


But you are wrong, read again. There are exactly four possibilities
of accessing a form element in a standards-compliant way: The
namedItem(...) method, the index operator with a string operand, the
item(...) method and the index operator with a numeric operand. The
index operator (`[...]'), however is also downwards compatible as the
`document.forms ' and `elements' collections or arrays were already part
of "DOM Level 0" from IE 3.0 and NN 3.0 on while the namedItem(...)
and item(...) methods were not. So the saner way is using the index
operator as Lasse suggested.
PointedEars

P.S.
Your `From:' header does not contain an e-mail address and is therefore
invalid, so you are violating Internet standards, helping to destroy the
Internet. ---> http://www.interhack.net/pubs/munging-harmful/
Jul 20 '05 #9
JRS: In article <3F************ **@PointedEars. de>, seen in
news:comp.lang. javascript, Thomas 'PointedEars' Lahn
<Po*********@we b.de> posted at Mon, 8 Dec 2003 03:39:21 :-
Your `From:' header does not contain an e-mail address and is therefore
invalid, so you are violating Internet standards, helping to destroy the
Internet. ---> http://www.interhack.net/pubs/munging-harmful/


Perhaps he does not want to receive long-winded and pointless messages
from such as yourself. I trust that you will have the courage of your
convictions, and will not attempt to use any addresses other than those
literally provided.

I advise you to stop nagging; it makes you look foolish.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - FAQqish topics, acronyms & links;
some Astro stuff via astro.htm, gravity0.htm; quotes.htm; pascal.htm; &c, &c.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7414
by: mappo | last post by:
There are about a million posts on how to get rid of the extra space _after_ the form end-tag, but I can't find any that solve my problem: extra space _in_ the form tag. I have a table nestled inside the form and since I want the submit button underneath the input text field i have a br tag to separate them. For some reason IE5.5 gives me...
9
2456
by: Markus Ernst | last post by:
Hi I am building an admin environment for a CMS system. For the issues described I have a testcase available at http://www.ernstdeslebens.ch/csstest/ I am sorry the links are not useable as they lead to password-protected pages; it is only this page for demonstration. Both HTML (strict) and CSS validate.
11
4153
by: Pete Wilson | last post by:
Hi folks -- The page at http://www.pwilson.net/submit-demo.html will not validate. The validator at http://validator.w3.org tells me I can't have an input inside a form. Would some kind soul please tell me what I'm doing wrong?
4
9948
by: Matthew Louden | last post by:
It happend to me more than once. When I create web controls or move the positions in VS.NET, I encountered the following run-time errors: It doesn't matter what controls I create, the following 'checkbox' control is just an example. Control 'CheckBox1' of type 'CheckBox' must be placed inside a form tag with runat=server. Description: An...
6
787
by: ste.paoletti | last post by:
hi, I have read that browsers support block element inside inline element but the css is not valid. Someone can tell me more about? What do you think? Thanks.
14
19362
by: Luciano A. Ferrer | last post by:
It is ok tu use a table tag inside a form tag? (you know, you do not use h2 inside p, etc...) -- Luciano A. Ferrer laferrerQuiTadme@SacaDMEgmail.com .... un todo en uno y uno en todo
5
2535
by: plumba | last post by:
Hi all I have a form (see below), which for some reason has decided to stop functioning all together. It just does not call up the function. It is called up in the opening <form> tag but fails.... Any ideas??? <html> <head><title>New Details</title> </head> <center> <H2><IMG SRC="$(path)smlogo.gif"><br>
6
2180
by: shapper | last post by:
Hello, I am creating a form that includes a few JQuery scripts and TinyMCE Editor: http://www.27lamps.com/Beta/Form/Form.html I am having a few problems with my CSS: 1. Restyling the Select
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.