From: Jukka K. Korpela on
Richard Cornford wrote:

> Valid HTML is a good idea, but why add ID attributes to form controls
> that already need to have NAME attributes in order to be
> 'successful' (submitted to the server)?

To make it simpler to access the form fields individually, and to associate
label elements with them, as required for accessibility.

> Bad as it is, with the correct use of case in the Identifiers your
> code would 'work'.

For some unspecified values for "work".

--
Yucca, http://www.cs.tut.fi/~jkorpela/

From: Stefan Weiss on
On 28/06/10 21:43, jr wrote:
> On Jun 28, 12:22 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
>> You want to *finally*(!) read the FAQ and don't ever do that again. Even a
>> document where you have no URL for does not need to be posted verbatim in
>> order to demonstrate the problem. In fact, creating a reduced test case is
>> very likely to show the problem to you without posting it. And get a real
>> name.
>>
>> <http://jibbering.com/faq/#posting>

> ok, thanks for the link. I would like to read it but the jibbering
> site seems to be down.

Wouldn't be the first time. Google has all of it cached, though, so you
can still read it by searching for "cache:jibbering.com/faq". Or just
click here:

http://webcache.googleusercontent.com/search?q=cache:7jGjZFWhwsgJ:www.jibbering.com/faq/

By the way, I agree with Thomas Lahn, you really shouldn't just quote
everything when you post a reply. If you're unsure of how and what to
quote, read this page:

http://www.netmeister.org/news/learn2quote.html


--
stefan
From: Thomas 'PointedEars' Lahn on
Jukka K. Korpela wrote:

> Richard Cornford wrote:
>> Valid HTML is a good idea, but why add ID attributes to form controls
>> that already need to have NAME attributes in order to be
>> 'successful' (submitted to the server)?
>
> To make it simpler to access the form fields individually,

That is only required if there is more than one form control with the same
name, and even then it is doubtful whether there is a real use case.

> and to associate label elements with them, as required for accessibility.

Good point. It is without positive relevance to scripting, though.

Relevant to scripting is that a) IDs create properties of a host object in
the scope chain in MSHTML, which spoils script namespaces and b) that it
tends to be less efficient to make a user-level method call to look up an
element with a specific ID in the whole document (the larger the document,
the less efficient) instead of using a built-in collection relevant to only
a subtree (in particular when the context object can be easily referred to,
as here). Reduced compatibility of the call can be another issue, although
it is unlikely nowadays; incidentally, for the same reason you are unlikely
to need document.getElementById(...) to look up a form control by ID as
HTMLCollection::namedItem() as triggered by the bracket property accessor
syntax is specified and implemented to work both with names and IDs.

We have been over this ad nauseam here. Read, think, post. In that order.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(a)news.demon.co.uk>
From: SAM on
Le 6/28/10 5:51 PM, jr a �crit :
> I fixed what you suggested on Sunday, valid html and added the field
> id's.. Below is the view source.
> I cannot list the web page because it is an internal server.
> You suggested to use a SelectedIndex instead of the option select and
> testing for whether the selectedIndex value matches the index of that
> option.
> I will try it, I do want to vaidate for user errors. In order to do it
> I have to change the way mysql pulls the data from the database.
> First, I would like to get one of the validations to work. Right now
> this line doesn't work at all.

because of :

with(thisform) { blah about DOM objects }

the blah about DOM elements would have to be enough

But ... it is always much better to use the form's elements :
document.forms[0].elements['bu']

> I'm not getting any messages so something
> is wrong with the javascript or the onsubmit .

the 2nd } of with(thisform) { }
is missing ...

> method='post' onsubmit='return validate_form(this);
>
> Should it be (thisform) instead of (this)??
> thanks,
> ---------------view source--------
>
> <html>
> <head>
> <title>Print Barcode Labels</title>

<script type="text/javascript">
function validate_form(thisform) {
if ( thisform['bu'].value=='' ) {
alert('No right BU selected ! Make another choice.');
thisform['bu'].focus();
return false;
}
if ( thisform['search_zoneid'].value == '') {
alert('Search zone is empty !');
thisform['search_zoneid'].focus();
thisform['search_zoneid'].select();
return false;
}
if ( thisform['search_zonenm'].value == '') {
alert('Missing zone number !');
thisform['search_zonenm'].focus();
thisform['search_zonenm'].select();
return false;
}
return true;
}
</script>

> </head>
>
> <body>
>
>
> <h2 align='center'>Print Barcode Lables</h2>
> <form enctype='multipart/form-data' action='' method='post'
> onsubmit='return validate_form(this);'><table cellpadding='3'
> cellspacing='0' border='0' style='border:1px solid #CCCCCC'
> align='center'>
> <th colspan='2'><span class='ast'>*</span>Search for Labels to Print
> <tr>
> <th align='right'><span class='ast'>*</span>BU
> <td><select name='bu' >
> <option value=''>Select BU</option>
> <option value='08005'>08005</option>
> <option value='08010'>08010</option>
> <option value='08020'>08020</option>
> <tr>
> <th align='right'>Zone ID
> <td><input type='text' name='search_zoneid' size='20' id='zoneid'>
> <tr>
> <th align='right'>Zone Number
> <td><input type='text' name='search_zonenm' size='20' id='zonenm'>
> <tr>
> <th align='right'>NDC
> <td><input type='text' name='search_nationalDrugCode' size='20' >
> <tr>
> <td align='center' colspan='2'><input type='submit' value='Search'>
> </table>
> <tr>
> <td><span class='ast'>*</span> - <font size='-1'><i>Required</i>
> </table>
> </form></body>
> </html>
From: Richard Cornford on
On Jun 28, 9:03 pm, Jukka K. Korpela wrote:
> Richard Cornford wrote:
>> Valid HTML is a good idea, but why add ID attributes to form
>> controls that already need to have NAME attributes in order
>> to be 'successful' (submitted to the server)?
>
> To make it simpler to access the form fields individually,

Making something simpler implies a change (in relative simplicity).
The mechanisms for accessing from controls that have NAME attributes
is already very simple, given that for all scriptable web browsers a
single approach to accessing form controls has been possible (avoiding
the branching that has been so common in other areas of browser
scripting, with the formalisation and standardisation of that approach
implying its continuing validity for the indefinite future). Adding to
the mark-up for the sake of using an alternative means of accessing
the form controls is more than enough to negate any (questionable)
increase in simplicity that looking up elements by ID may offer in the
javascript.

It is not always useful to access fields individually. For example,
like-named radio buttons are rarely of interest individually in
javascript form validation processes.

> and to associate label elements with them, as required
> for accessibility.

That is a good reason for using ID attributes in the mark-up, and if
they are going to be there they will be available for other purposes,
such as accessing the form controls. But then accessing the form
controls is not the reason for putting them there, nor something for
which they are necessary.

>> Bad as it is, with the correct use of case in the Identifiers
>> your code would 'work'.
>
> For some unspecified values for "work".

Yes, the mark-up not containing any element with the ID 'bu' means
that it would not functions in environments which don't (erroneously)
return NAMEd element from - getElementById -, but IE, for one, would
execute the code to one of the more probably desirable outcomes.

Richard.