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