A page has elements without id – only with names. How to access them by javascript like this?
document.getElementById('id').value := "...";
UPDATED:
Thanks to all! Is it possible to access then to element with specified value (radiobutton)?
<nobr><label><input style="vertical-align:middle" type="radio" name="name" value="value1" checked="checked"/><span style="vertical-align:middle" class="label">value1</span></label></nobr><br/>
<nobr><label><input style="vertical-align:middle" type="radio" name="name" value="value2"/><span style="vertical-align:middle" class="label">value2</span></label></nobr><br/>
The other answers cover your original question. Regarding your update about accessing by value, there is no
getElementsByValue()function, but if it is your intention to select the particular radio button that has both a specified name and value you can do something like this:Above function will return a reference to the first matching element or null if nothing matched. If you want to allow for more than one element with the same name and value you could modify this to return an array (though I don’t know why you’d have more than one element with the same name and value, at least not with radio buttons).
Note that also this can easily be modified to return a reference to the currently checked element, just change the if in the loop to be
if (els[i].checked).You may be able to do some or all of this using
document.querySelector(), but I don’t use it myself because I need to support older IE. You can definitely replace all of the above with one line of jQuery.