javascript alert is not showing If I left that and click submit

Viewed 6

Currently, I'm trying to show the alert if I skip to choose YES/NO radio button. But alert didnt show and also, it shows Uncaught TypeError: Cannot read properties of null (reading 'value'). If I choose and click Submit, it knows the values but if I left as blank. It cause that error. May I know why it is causing that error? Both 4 are radio buttons.


Is the packing properly vacuum sealed? : YES
NO


Is the packing canister/substrate box damaged? : YES
NO


If canister packing, are there interleaves and pink foam avaliable? : YES
NO


Is there any silicon dust inside ESD sealing bag? : YES
NO

Below is Javascipt.

var pk = document.querySelector('input[type=radio][name=pkyes]:checked').value;
if (pk == '' || pk == null ){
    alert('Please Choose YES or NO for packing vacuum seal or not.')
}
var pkdmg = document.querySelector('input[type=radio][name=pkdamage]:checked').value;
var canis = document.querySelector('input[type=radio][name=canispak]:checked').value;
var celidst = document.querySelector('input[type=radio][name=silicondst]:checked').value;
0 Answers
Related