Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > hidden input type and the dom

Reply
Thread Tools

hidden input type and the dom

 
 
aidy.lewis@googlemail.com
Guest
Posts: n/a
 
      07-04-2007
Hi,

Could someone tell me how I can reference a hidden input type using
the DOM?

Aidy

 
Reply With Quote
 
 
 
 
David Dorward
Guest
Posts: n/a
 
      07-04-2007
On Jul 4, 4:06 pm, "(E-Mail Removed)"
<(E-Mail Removed)> wrote:

> Could someone tell me how I can reference a hidden input type using
> the DOM?


http://developer.mozilla.org/en/docs...ng_the_W3C_DOM

--
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/

 
Reply With Quote
 
 
 
 
y2ee.asdf@gmail.com
Guest
Posts: n/a
 
      07-04-2007
On Jul 4, 11:06 am, "(E-Mail Removed)"
<(E-Mail Removed)> wrote:
> Hi,
>
> Could someone tell me how I can reference a hidden input type using
> the DOM?
>
> Aidy


You're hidden input needs to be in the following format:

<input type="hidden" id="myHiddenInput" value="myHiddenValue" />

Then you may reference is as follows:

var hiddenInput = document.getElementById("myHiddenInput");
alert(hiddenInput.value);

This will display myHiddenValue in an alert box.

Hope this helps.

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      07-04-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On Jul 4, 11:06 am, "(E-Mail Removed)"
> <(E-Mail Removed)> wrote:
>> Could someone tell me how I can reference a hidden input type using
>> the DOM?
>>
>> Aidy

>
> You're hidden input needs to be in the following format:
>
> <input type="hidden" id="myHiddenInput" value="myHiddenValue" />


It would be wrong to include the slash at the end in an HTML document
(and as IE browsers do not comprehend XHTML it would not be a good idea
to contemplate writing, and especially scripting, XHTML documents).
Also, an INPUT element without a NAME attribute would not result in a
name value pair being sent to the server if the containing form was
submitted.

> Then you may reference is as follows:
>
> var hiddenInput = document.getElementById("myHiddenInput");
> alert(hiddenInput.value);

<snip>

It is always better to use the W3C HTML DOM specified - elements -
collection of the FORM element to reference the form controls it
contains. They can be referenced in that collection by NAME, ID or
index, but given that they must have a NAME attribute to be useful in
form submission it makes most sense to use that NAME attribute's value.
See:-

<URL: http://jibbering.com/faq/faq_notes/form_access.html >

Richard.

 
Reply With Quote
 
Peter Michaux
Guest
Posts: n/a
 
      07-05-2007
On Jul 4, 2:44 pm, "Richard Cornford" <(E-Mail Removed)>
wrote:
> (E-Mail Removed) wrote:
> > On Jul 4, 11:06 am, "(E-Mail Removed)"
> > <(E-Mail Removed)> wrote:
> >> Could someone tell me how I can reference a hidden input type using
> >> the DOM?

>
> >> Aidy

>
> > You're hidden input needs to be in the following format:

>
> > <input type="hidden" id="myHiddenInput" value="myHiddenValue" />

>
> It would be wrong to include the slash at the end in an HTML document


I ran into this a few days ago. The W3C validator allows the slash and
is happy without it also.

For example the following does validate.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Page Title</title>
</head>
<body>
<form action="#">
<p><input type="hidden" id="myHiddenInput" value="myHiddenValue" /
></p>

</form>
</body>
</html>

Peter

 
Reply With Quote
 
y2ee.asdf@gmail.com
Guest
Posts: n/a
 
      07-05-2007
<snip>

> > <input type="hidden" id="myHiddenInput" value="myHiddenValue" />

>
> It would be wrong to include the slash at the end in an HTML document
> (and as IE browsers do not comprehend XHTML it would not be a good idea
> to contemplate writing, and especially scripting, XHTML documents).


IE complains only when the XHTML is served as an xml document. When
served as HTML, it can render fine.

> Also, an INPUT element without a NAME attribute would not result in a
> name value pair being sent to the server if the containing form was
> submitted.


Agreed, but the question was with regards to referencing the hidden
input using JavaScript. Server-side processing of the form is a
different story.

>
> > Then you may reference is as follows:

>
> > var hiddenInput = document.getElementById("myHiddenInput");
> > alert(hiddenInput.value);

>
> <snip>
>
> It is always better to use the W3C HTML DOM specified - elements -
> collection of the FORM element to reference the form controls it
> contains.


<snip>

I would accept this if you could provide an official w3 recommendation
that supports it.

Thanks.

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      07-05-2007
Peter Michaux wrote:
> On Jul 4, 2:44 pm, Richard Cornford wrote:
>> (E-Mail Removed) wrote:
>>> On Jul 4, 11:06 am, "(E-Mail Removed)"

<snip>
>>> You're hidden input needs to be in the following format:

>>
>>> <input type="hidden" id="myHiddenInput" value="myHiddenValue" />

>>
>> It would be wrong to include the slash at the end in an HTML document

>
> I ran into this a few days ago. The W3C validator allows the slash and
> is happy without it also.


The slash is valid in SGML, it just does not mean what it may be take to
mean. It is actually a shortcut for:-

<input type="hidden" id="myHiddenInput" value="myHiddenValue">&gt;

- though browsers do not recognise those SGML shortcuts, even if SGML
validators do. Try putting one inside the HEAD (on a LINK or META)
element and see if the validator does not complain about text appearing
in a context where text is not allowed (or the HEAD being explicitly
closed after it has been implicitly closed by the out of context text).

Richard.

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      07-05-2007
(E-Mail Removed) wrote:
> <snip>
>
>> > <input type="hidden" id="myHiddenInput" value="myHiddenValue" />

>>
>> It would be wrong to include the slash at the end in an HTML
>> document (and as IE browsers do not comprehend XHTML it would
>> not be a good idea to contemplate writing, and especially
>> scripting, XHTML documents).

>
> IE complains only when the XHTML is served as an xml document.


IE does not complain, it just applies an inbuilt XSLT to the XML of the
mark-up and displays the result as an HTML document that relates to the
XML source code.

> When served as HTML, it can render fine.


You mean that when you tell the browser that the document is HTML it
parses it with its tag-soup HTML parser and error-corrects all the
nonsense in the mark-up back to an HTML document that it can cope with?
That makes it an HTML document with correctable errors not an XHTML
document.

You are forgetting that our subject here is browser scripting so we have
an absolute test for whether a document is XHTML or HTML and that is
whether the receiving browser exposes an XHTML DOM or an HTML DOM to be
scripted. If the browser exposes an XHTML DOM then the document was an
XHTML document, if an HTML DOM then it was an HTML document. And as
almost no non-trivial browser scripts can cope with both XHTML and HTML
DOMs that distinction is very significant. IE browsers do not support
XHTML and so they just cannot expose an XHTML DOM to be scripted. And as
commercial scripting is pretty much required to support (or be supported
by) IE, commercial scripts are HTML DOM scripts. They requre that the
browser interpret their related documents _only_ as HTML (tag-soup or
not) and that makes it insane to author documents with XHTML-style
mark-up and then script it on assumption that it will _never_ be
interpreted as XHTML by a browser. That path just leaves people to be
confused about what they are really doing.

>> Also, an INPUT element without a NAME attribute would not result
>> in a name value pair being sent to the server if the containing
>> form was submitted.

>
> Agreed, but the question was with regards to referencing the hidden
> input using JavaScript. Server-side processing of the form is a
> different story.


If the elements must have names in order to be useful then they don't
need to have IDs in order to be meaningfully referenced in the DOM.

>> > Then you may reference is as follows:

>>
>> > var hiddenInput = document.getElementById("myHiddenInput");
>> > alert(hiddenInput.value);

>>
>> <snip>
>>
>> It is always better to use the W3C HTML DOM specified - elements -
>> collection of the FORM element to reference the form controls it
>> contains.

>
> <snip>
>
> I would accept this if you could provide an official w3
> recommendation that supports it.


How would a W3C recommendation support the assertion that accessing
through the DOM specified collections is better than using -
getElementById -? That is not of relevance to what a W3C recommendation
is.

Using the collections is better because they are more widely and more
consistently supported (allowing a one-code-fits-all-browsers style of
authoring (which results in code that is cheep to create and maintain
and very reliable)), self-documenting (because the appearance of -
forms - and - elements - in the code makes it very clear what types of
elements are being referenced/used) and the resolving of the element
references is generally much faster because the references are looked up
in smaller, more specific, collections. With speed, reliability,
consistency and ease of maintenance on their side the label 'better' is
hard to dispute.

Richard.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: length of input type hidden =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBNVlA=?= ASP .Net 0 09-17-2004 11:57 AM
can i pass data with input text instead of input hidden? Walter ASP General 6 09-17-2004 11:16 AM
input type=hidden simon ASP .Net 3 05-26-2004 12:25 PM
server control that will render <input type="hidden"` neverstill ASP .Net 3 01-05-2004 09:22 PM
How to create HIDDEN Input element using DOM Raghuram Banda Javascript 1 11-05-2003 06:08 PM



Advertisments