473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

XHTML 1.1 vs name="abc"

I had a page that works when setup like this:

===
<form name="frmCalc" action="">

<script type="text/javascript">

function btnCalc_onclick(abc) {
return "got here with " + abc;
}

</script>

<p>
<textarea name="tareaResults" rows="2" cols="20"></textarea>
</p>
<p>
<input type="button" value="Calculate" name="btnCalc"
onclick="document.frmCalc.tareaResults.value=btnCa lc_onclick('ghijk');" />
</p>

</form>
===

In trying to upgrade and validate it as XHTML 1.1, the name attribute
invariable seems to make the validator gag.

I can validate it by changing to:

===
<form id="frmCalc" action="">
....
<textarea id="tareaResults" rows="2" cols="20"></textarea>
....
<input type="button" value="Calculate" id="btnCalc"
onclick="document.frmCalc.tareaResults.value=btnCa lc_onclick('ghijk');" />
....
===

But now the script gags when executed: "document.frmCalc.tareaResults is
null or not an object."

Somewhere I read thet getElementById was the "magic bullet. So I tried
constructions like this with no joy:

===
....
<input type="button" value="Calculate" id="btnCalc"
onclick="document.getElementById('frmCalc').getEle mentById('tareaResults').value=btnCalc_onclick('gh ijk');"
....
===

I've spent lots of the day trying to google a solution with no joy.

My Qs:

1) what's a construction for the onclick attribute that will work with the
id="frmCalc" and id="tareaResults"???

2) what defines the rules for interpreting the contents of the onclick
attribute? javascript/ecmascript? XHTML1.1? In other words, where are the
rules defined that tell me why what I'm doing isn't working and what to do
instead?

Thanks in advance!
Feb 11 '07 #1
6 2273
On Feb 11, 2:19 am, "Dick Watson" <littlegreenge...@mind-enufalready-
spring.comwrote:
<input type="button" value="Calculate" id="btnCalc"
onclick="document.getElementById('frmCalc').getEle mentById('tareaResults'). value=btnCalc_onclick('ghijk');"
At first sight, you've very close. getElementById's scope is the whole
document, just say: document.getElementById('tareaResults').value=blah

Feb 11 '07 #2
Gee that was easy. Where were you at 11:30 this morning? Thanks!

BTW, the second question still stands--what defines the syntax, etc., of the
parameter in onclick="parameter"? Is it javascript? Is it XHTML? DOM?

"Emmanuel" <sa******@gmail.comwrote in message
news:11*********************@v45g2000cwv.googlegro ups.com...
On Feb 11, 2:19 am, "Dick Watson" <littlegreenge...@mind-enufalready-
spring.comwrote:
><input type="button" value="Calculate" id="btnCalc"
onclick="document.getElementById('frmCalc').getEl ementById('tareaResults').value=btnCalc_onclick('g hijk');"

At first sight, you've very close. getElementById's scope is the whole
document, just say: document.getElementById('tareaResults').value=blah

Feb 11 '07 #3
On Feb 11, 11:19 am, "Dick Watson" <littlegreenge...@mind-enufalready-
spring.comwrote:
I had a page that works when setup like this:

===
<form name="frmCalc" action="">

<script type="text/javascript">

function btnCalc_onclick(abc) {
return "got here with " + abc;

}

</script>

<p>
<textarea name="tareaResults" rows="2" cols="20"></textarea>
</p>
<p>
<input type="button" value="Calculate" name="btnCalc"
onclick="document.frmCalc.tareaResults.value=btnCa lc_onclick('ghijk');" />
The best way to get a reference from the button to the form is to use
"this.form", but that doesn't really answer your question. :-)

Another answer is that using XHTML on the web, served as XHMTL, will
cause you never-ending headaches for zero benefit. Given that the
vast majority of users out there are using a browser that doesn't know
what XML is, you have to serve HTML to those users anyway.

You might decide to use content negotiation and serve XHTML to some
browsers and HTML to others, but what's the point? Just use HTML 4.01
strict and your HTML will work from now till doomsday in every decent
browser in use (which is pretty much any browser released in the last
10 years).

Script and DOM support is another matter...

</p>

</form>
===

In trying to upgrade and validate it as XHTML 1.1, the name attribute
invariable seems to make the validator gag.
XHTML 1.1 removes support for deprecated elements and attributes -
support for the name attribute for forms has been removed, as you
discovered.
>
I can validate it by changing to:

===
<form id="frmCalc" action="">
...
<textarea id="tareaResults" rows="2" cols="20"></textarea>
...
<input type="button" value="Calculate" id="btnCalc"
onclick="document.frmCalc.tareaResults.value=btnCa lc_onclick('ghijk');" />
...
===

But now the script gags when executed: "document.frmCalc.tareaResults is
null or not an object."

Somewhere I read thet getElementById was the "magic bullet. So I tried
constructions like this with no joy:
For the form element, yes, but not for form controls. They *must*
have a name or they won't be submitted with the form.
>
===
...
<input type="button" value="Calculate" id="btnCalc"
onclick="document.getElementById('frmCalc').getEle mentById('tareaResults'). value=btnCalc_onclick('ghijk');"
getElementById is a method of the document, not an element. If you
want to get references that way just go directly to the element you
want:

document.getElementById('tareaResults')...
or to go via the form:

document.getElementById('frmCalc').tareaResults.va lue ...

or:
document.getElementById('frmCalc').elements['tareaResults'].value ...

But using IDs on form controls can get confusing, I prefer to just use
names as they are needed anyway, why add an ID unless there's a
compelling need for it?

...
===

I've spent lots of the day trying to google a solution with no joy.

My Qs:

1) what's a construction for the onclick attribute that will work with the
id="frmCalc" and id="tareaResults"???
Use an ID for the form. You can give form controls both name and ID
attributes, but that gets messy with things like radio buttons, so
just use name unless you really want an ID.
>
2) what defines the rules for interpreting the contents of the onclick
attribute? javascript/ecmascript? XHTML1.1?
The HTML 4 specifiction in conjunction with the XHTML 1.1
specification, plus the various DOM Level 2 specifications (Core,
HTML, Event, etc.) and the DOM Level 3 specifications.
In other words, where are the
rules defined that tell me why what I'm doing isn't working and what to do
instead?
<news: comp.lang.javascript >

<news: comp.infosystems.www.authoring.html >
<URL: http://groups.google.com.au/group/
comp.infosystems.www.authoring.html/topics?lnk=li&hl=en >

<news: comp.infosystems.www.authoring.stylesheets >
<URL: http://groups.google.com.au/group/
comp.infosystems.www.authoring.stylesheets/topics?lnk=li&hl=en >

--
Rob

Feb 11 '07 #4
RobG wrote:
<snip>
document.getElementById('frmCalc').tareaResults.va lue ...
Referencing named or IDed form controls as named members of a FORM
element is non-standard and effectively relying upon a 'shortcut' that
has been observed as consistently available in HTML DOMs but is not
necessarily available in XHTML DOMs. If the intention here is to use
XHTML, as opposed to just giving the mark-up author the illusion of using
XHTML, then this would be a bad alternative.
or:
document.getElementById('frmCalc').elements['tareaResults'].value
<snip>

or:-

document.forms['frmCalc'].elemnts['tareaResults'].value

- as the W3C HTML DOM specification requires that IDed FORM elements may
be referenced as named members of the - document.forms - collection.

Richard.

Feb 11 '07 #5
Buy, that's a lot of places to define one simple attribute. No wonder I
couldn't find a simple answer. It would certainly be easier to develop for
the web if the standards lawyers would find some other problem to work on
for a while...

Thanks for your informative post!

"RobG" <rg***@iinet.net.auwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
>2) what defines the rules for interpreting the contents of the onclick
attribute? javascript/ecmascript? XHTML1.1?

The HTML 4 specifiction in conjunction with the XHTML 1.1
specification, plus the various DOM Level 2 specifications (Core,
HTML, Event, etc.) and the DOM Level 3 specifications.
>In other words, where are the
rules defined that tell me why what I'm doing isn't working and what to
do
instead?

<news: comp.lang.javascript >

<news: comp.infosystems.www.authoring.html >
<URL: http://groups.google.com.au/group/
comp.infosystems.www.authoring.html/topics?lnk=li&hl=en >

<news: comp.infosystems.www.authoring.stylesheets >
<URL: http://groups.google.com.au/group/
comp.infosystems.www.authoring.stylesheets/topics?lnk=li&hl=en >

Feb 11 '07 #6
On Feb 11, 10:22 pm, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
RobG wrote:

<snip>
document.getElementById('frmCalc').tareaResults.va lue ...

Referencing named or IDed form controls as named members of a FORM
element is non-standard and effectively relying upon a 'shortcut' that
has been observed as consistently available in HTML DOMs but is not
necessarily available in XHTML DOMs. If the intention here is to use
XHTML, as opposed to just giving the mark-up author the illusion of using
XHTML, then this would be a bad alternative.
Fair enough, I was relying upon (probably insufficient) testing.

[...]
or:-

document.forms['frmCalc'].elemnts['tareaResults'].value

- as the W3C HTML DOM specification requires that IDed FORM elements may
be referenced as named members of the - document.forms - collection.
In compliant browsers, maybe (typo excepted) - but unfortunately at
least one reasonably common one (Safari) appears not to be and it
fails for XHTML documents, although it works fine for HTML documents.
Perhaps I should have mentioned that.
--
Rob

Feb 12 '07 #7

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

Similar topics

6
by: Jochen Daum | last post by:
Hi ! If I have an input field <form ... method="post"> <input type="text" name="abc def"> </form>
9
by: msnews.microsoft.com | last post by:
Hello! I'm Jim by asp How can show "abc" in textbox when click one botton?
21
by: strutsng | last post by:
<input type="file"> only allows the user to browse for files. How about "browse for folder" dialog? Can html/javascript do that? I couldn't find any syntax for that. If not, please advise what...
1
by: srinu | last post by:
Hello, We had one webserver based on a linux machine. The website is fully function and designed by a different person. Now we moved the machine from one IP to another one. I changed the...
7
by: Kirt | last post by:
i have walked a directory and have written the foll xml document. one of the folder had "&" character so i replaced it by "&amp;" #------------------test1.xml <Directory> <dirname>C:\Documents and...
5
by: Damiano ALBANI | last post by:
Hello, I'd like to write a single XML Schema for both these documents : <Items> <Item xml:id="id1"> <Name>ABC</Name> ... </Item> <Item xml:id="id2">
9
by: Steve | last post by:
Hi; I've being going through some legacy code on an old JSP site I have been patching. I noticed that when I save the JSP down to my PC as an HTML file I get this javascript error in IE 6 ( ...
7
by: MLH | last post by:
If I drop Like "*ABC*" in a QBE grid criteria cell, the records returned include mixed case. Can I force the uppercase limitation in a QBE grid?
7
by: neovantage | last post by:
Hey all, I am creating a xml file in this format <?xml version="1.0" encoding="utf-8" standalone="yes"?> <customers> <customer> <category>Brosch&uuml;ren</category> ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...

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.