0

I thought if it is possible to get this done with PHP or JavaScript:

Let's say I have two checkboxes:

<li><input type="checkbox" checked="checked" name="Tuesday" value="111"/> Tueday</li>
<li><input type="checkbox" name="Wednesday" value="112"/> Wednesday</li> 

I want to see the value of the checked="checked" which is 111 after the page is loaded.

How can i achieve this? If this is possible in PHP and JavaScript, I would like to have both methods. Thank you!

Erik Schierboom
  • 16,301
  • 10
  • 64
  • 81
Andrei
  • 497
  • 2
  • 8
  • 18

1 Answers1

0
window.addEventListener('load', function(){
    var ch = document.getElementsByName('Tuesday')[0];
    if(ch.checked)
        // use ch.value
});

Or if you want to display checked values:

window.addEventListener('load', function(){
    var checkedValues= [];
    var chs = document.getElementsByTagName('input');
    for(var i = 0; i < chs.length; i++)
        if(chs[i].type.toLowerCase() === 'checkbox' && chs[i].checked)
            checkedValues.push(chs[i].value);
    // use checkedValues
});
karaxuna
  • 26,752
  • 13
  • 82
  • 117