Home>
Requirements
  • I want to count the number of checkboxes checked when a button is pressed
Current status

Cannot read property when trying to get withdocument.getelementbyIdwhen getting the state of a checkbox whose initial value is false I get a 'checked' of nullerror. When the initial value is true and the check box is set to false, it can be obtained withdocoument .... How can I get a checkbox with an initial value of false?
The application is vue, but there is no choice but to use plain javascript because of common parts.

Does the initial bool value determine whether it can be obtained or not? ?
// If the initial value is true, it can be obtained as follows, but if it is false, it cannot be obtained.
document.getElementById ('row_0'). checked

Is there any way to write a value when the initial value of the check box is false (or get the value regardless of the initial value)? ? ?
  • Answer # 1

      

    Is it possible or not to be determined by the initial bool value? ?

    That's not true. Make sure that the ID is in thedocumentproperly (If it is generated by Vue.js, it may be a failure to get it at the timing before generation).

  • Answer # 2

    If you get an error, read the error message.
    Cannot read property 'checked' of null
    There is.

    I can't read null 'checked'.
    That means your code is not a second checkbox
    Because we are trying to read checked against null.

    document.getElementById ('row_0')
    document.getElementById ('row_1')
    You can see it by running

    .
    There's just norow_1.row_1has not been generated because you made a code mistake before "plain JavaScript" you say.

      

    If the initial value is true, you can get it below, but if it's false, you can't get it

    That's not the case.
    If you get an error, don't ask immediately, but if this is the case, try the following first.

    Try setting the initial value of row_0 to false

    Try setting the initial value of row_1 to true

    Try withdocument.getElementById ('row_1')

  • Answer # 3

      

    Cannot read property 'checked' of null error when trying to get with document.getelementbyId when getting the state of the check box whose initial value is false (the state when the button is pressed is irrelevant) The When the initial value is true and the check box is set to false, it can be obtained with document ... How can I get a checkbox with an initial value of false?

    Put a reference link.
    An accurate answer is not possible without looking at the code.

    https://qiita.com/k_0214/items/672c5db1184a46b99273
    https://StackOverflow.com/questions/190875

  • Answer # 4

    For now, just the base

    
    
    


    There is no particular problem
    If it is not a source problem, it may be a problem with the operating environment such as the OS or browser