On 08/04/2005 07:05, Jukka K. Korpela wrote:
[snip]
Quote:
There are different ways of referring to a FORM element in client-side
code, including document.forms[0] (assuming it's the only form on a
page), which is legacy JavaScript, |
I wouldn't exactly say the forms collection is a legacy property. In
fact, the DOM HTML module has brought it quite up-to-date with regard
to accessing FORM elements by id.
Personally, I find
var form = document.forms['aFormID'];
far more appealing than
var form = document.getElementById('aFormID');
Certainly, if real legacy code was required (to support NN4, for
example) one would simply need to add a name attribute to the FORM
with the same value and the first statement would work without issue.
By the way, I think that perhaps a better combined example than that
shown in <URL:http://www.cs.tut.fi/~jkorpela/forms/navmenu.html> would be:
function jump(form) {
var url = form.elements['url'],
sI = url.selectedIndex;
if(0 < sI) {location.href = url.options[sI].value;}
return false;
}
<form action="http://www.cgiforme.com/jumporama/cgi/jumporama.cgi"
method="post" onsubmit="return jump(this);">
<div><select name="url">
<option value="http://www.cs.tut.fi/~jkorpela/forms/jsnav.html"
selected>Please select an item:</option>
<option value="http://www.cs.tut.fi/~jkorpela/forms/"
Quote:
Main page on HTML forms</option
option value="http://www.cs.tut.fi/~jkorpela/forms/choices.html"
Choices in HTML forms</option
option value="http://www.cs.tut.fi/~jkorpela/forms/tables.html"
Tables and forms</option
option value="http://www.cs.tut.fi/~jkorpela/forms/methods.html"
Form submission methods (GET and POST)</option
/select
|
<input type="submit" value="Go!"></div>
</form>
This avoids any need for form identification, and gets rid of the
auto-selection. If the latter was really desired, the onchange
attribute could still use the jump function, with a small modification:
function jump(url) {
var sI = url.selectedIndex;
if(0 < sI) {location.href = url.options[sI].value;}
}
<select name="url" onchange="jump(this);">
Of course, I do agree that normal links are better.
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.