Code:
var input = document.getElementsByName(name).value;
Still very wrong.
getElementsByName() returns an *ARRAY* of all elements on the page with that name.
Even if there is only one by that name.
So if you *KNOW* there is only one by that name:
Code:
var input = document.getElementsByName(name)[0].value;
But that fails miserably if, for example, you have a set of 5 checkboxes all with the same name.
**********
Almost always, a better way to do this is to use the <form> to reference its member <input>s.
Example HTML:
Code:
<form id="myForm">
<input name="username" /><br/>
<input name="address" /><br/>
<label><input type="radio" name="gender" value="m" checked> Male</label>
<label><input type="radio" name="gender" value="f"> Female</label>
...
</form>
Then you can get fields in the form by name *MUCH* more simply. Example:
Code:
var form = document.getElementById("myForm");
var usernameValue = form.username.value;
var addressValue = form.address.value;
var genderValue = form.gender[0].checked ? "m" : "f";
And so on.