Form elements by getElementsByName
Here f_name is the name attribute of a textbox.
Output hereHere is the code for getting data entered inside a textbox by using value
In above code my_data is an array and its first element is my_data. If we have more number of elements with same name then we can get all values by using my_data as an array.
lengthmy_data.length : will give total number of elements using the same name.
Radio button using getElementsByNamemy_r1 my_r2 my_r3
Output hereOne group of radio buttons will have one common name. Here is the code to get selected radio button value by using getElementByName
Checkbox using getElementsByNameAll checkboxes will have common name.
Dropdown Listbox using getElementByNameselectedIndex Gives us the index number ( starting from 0 ) of selected option.
This article is written by plus2net.com team.