- I want to count the number of checkboxes checked when a button is pressed
Cannot read property when trying to get with
error. When the initial value is true and the check box is set to false, it can be obtained withdocument.getelementbyId
when getting the state of a checkbox whose initial value is false I get a 'checked' of nulldocoument ...
. 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
.
// 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
-
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.
You can see it by runningdocument.getElementById ('row_0') document.getElementById ('row_1')
.
There's just norow_1
.row_1
has 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 with
document.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
Related articles
- javascript - i want to get the value of ie currval in uwsc
- javascript - how to make a check box that can get the value for everyone by checking "everyone"
- javascript - i want to display the value entered in the created form in slack with incoming webhooks
- javascript - i want to get the value associated with the array key in the object
- javascript - recipe draft of the format check function of the character string defined date
- javascript - i can't get out of while
- javascript - when i display the value entered in the form, it is displayed as undefined
- swift - how to get api value on endpoint with pk
- javascript - how to get the progress on the server side
- javascript - get the value of the array in the object , how to use in an if statement
- javascript - i want to change the process using check in jquery
- i want to display the value obtained from postgresql with javascript on erb
- javascript - i want to receive and display a value in a dialog box
- javascript - i don't know how to get rakuten api json data
- javascript - i want to use a value initialized in one class in another unrelated class with no arguments
- javascript - about the return value of async
- javascript - i don't know how to get the json data for an array
- i want to get the coordinates of the javascript div area
- i want to get the coordinates of the javascript div area 2
- javascript - react how to write an input check
- javascript : Is it possible to specify multiple clsss of form->error?
- javascript : 3D graph in CSS or JS
- javascript : Changing the execution delay in a loop
- javascript : Loading an image depending on the width of the screen
- javascript : Why is the site slow in Safari?
- javascript : Website background and scrolling jump
- javascript : What template engine is right for this task?
- javascript : How to create a Js file for multiple modal windows?
- javascript : How to expand a block (div or other) to the other side? (HTML, CSS, React.js)
- javascript : Grid different rows, paired and unpaired
That's not true. Make sure that the ID is in the
document
properly (If it is generated by Vue.js, it may be a failure to get it at the timing before generation).