[SCRIPT]-CHECKBOX TO STRING JAVASCRIPT

CHECKBOX TO STRING JAVASCRIPT

Try this

riceChk = document.getElementById("rice");

You are getting value which is not valid for checkbox if you want to check for checked.

Also you have set alert before setting any value to price so it is undefined

This is happening because you are using the value before assign it.

var riceChk;
var price;

riceChk = document.getElementById("rice");

if (riceChk.checked == true){
    price="20";              
}else{
    price="riceChk wrong";//Just in case the flow is coming here.
}

alert(price);
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments