Click here to Skip to main content
15,868,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Team,
I have wrote the code as follows :
XML
<div class="input-append">
            <label>
                Processed :</label>
            <input type="checkbox" id="processedCheckBox" checked="checked" />
        </div>


What i want is
In One Checkbox,
Bydefault checkbox will be checked that means Yes
If i removed the checked from Checkbox that means No.
I want to put the value Yes and No
So how to do this.
Please Advice
Thanks
Harshal.
Posted
Updated 25-May-22 0:17am
Comments
Kornfeld Eliyahu Peter 30-Jun-14 9:44am    
Your question is somewhat unclear...
Where to put 'yes'/'no'?
R Harshal 30-Jun-14 9:49am    
Thanks For your Reply.
My question is :
if i checked the checkbox it should return me true which means YES.
if i Unchecked the checkbox it should return me false which means NO.
This I want .
Please Advice
Thanks
Harshal

The proper format of checkbox in HTML is...
JavaScript
<input type="chekbox" />
<input type="chekbox" checked="" />

...for unchecked/checked respectively...
If you want to turn the state of the checkbox to yes/no string yous have to use some JavaScript like this:
JavaScript
var ans = document.getElementById('checkbox_id').checked ? 'yes' : 'no';
 
Share this answer
 
Comments
R Harshal 30-Jun-14 10:10am    
Thank you so much Buddy .
Kornfeld Eliyahu Peter 30-Jun-14 13:08pm    
Glad to help...
Try this with JavaScript:
XML
<!DOCTYPE html>
<html>
<script>
function getCheckboxStatus(){
   var status = document.getElementById("processedCheckBox").checked;
   if (status) {
      alert("Yes");
   } else {
      alert("No");
   }
}
</script>
<body>
<div class="input-append">
     <label for="processedCheckBox">Processed :</label>
     <input type="checkbox" id="processedCheckBox" checked onchange="getCheckboxStatus()">
</div>
</body>
</html>
 
Share this answer
 
Comments
R Harshal 30-Jun-14 10:11am    
Thank You So much Buddy .
Peter Leow 30-Jun-14 10:36am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900