javascript - validate array of checkbox using getElementById -


i've got bunch of checkboxes defined array:

<input type="checkbox" value="1" id="courseinfo[]">content <input type="checkbox" value="2" id="courseinfo[]">reputation <input type="checkbox" value="3" id="courseinfo[]">duration <input type="checkbox" value="4" id="courseinfo[]">career <input type="checkbox" value="5" id="courseinfo[]">recommended <input type="checkbox" value="6" id="courseinfo[]">interests <input type="checkbox" value="7" id="courseinfo[]">other 

i trying see if last 1 (value=7) checked, tried:

q2 = document.getelementbyid("courseinfo[6]").value; 

that doesn't seem work.

how can access 7th 1 in array , check if been checked?

i want use pure javascript.

you don't have id attribute in checkbox collection. think you're meaning name attribute. use getelementsbyname elements nodelist. 6th element's value.

q2 = document.getelementsbyname("facilities")[6].value; 

use check if checkbox checked:

if(q2.checked) {    alert('you have checked 6th checkbox!'); } 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -