I want to change value when someone check or uncheck checkbox. Here is my code:
<?php
if($params['status'] == "2"){
?>
<div class="pull-right" id="confirm-ship">
<input type="checkbox" class="chkone"><br>
if(checkbox == check){
<span>Confirmed</span>
}else{
<span>Not Confirmed</span>
}
</div>
<?php
}
?>
I want to show message confirmed or not confirmed when someone click on checkbox without submit a page or reload a page. Is it possible, anyone help me?
I just added below code on above scenario just for giving an idea.
if(checkbox == check){
<span>Confirmed</span>
}else{
<span>Not Confirmed</span>
}
I want to change value when someone check or uncheck checkbox. Here is my code:
<?php
if($params['status'] == "2"){
?>
<div class="pull-right" id="confirm-ship">
<input type="checkbox" class="chkone"><br>
if(checkbox == check){
<span>Confirmed</span>
}else{
<span>Not Confirmed</span>
}
</div>
<?php
}
?>
I want to show message confirmed or not confirmed when someone click on checkbox without submit a page or reload a page. Is it possible, anyone help me?
I just added below code on above scenario just for giving an idea.
if(checkbox == check){
<span>Confirmed</span>
}else{
<span>Not Confirmed</span>
}
Share
Improve this question
edited May 26, 2017 at 12:37
Mantas Čekanauskas
2,2386 gold badges26 silver badges48 bronze badges
asked Sep 14, 2015 at 11:25
Muhammad AwaisMuhammad Awais
3033 silver badges16 bronze badges
5 Answers
Reset to default 4First you will need to set an event listener to listen for the change event and trigger a function.
If you give your elements id
's you can make things easier to target that element.
You will also want to place your javascript into <script>
tags. Some people place them in the body of the page or at the very bottom. Me personally, I like to place my in the <head>
tag as using window.onload
will only attempt to getElementById()
when the page has loaded.
window.onload=function(){ // Trigger when the page is ready
//Set change event
document.getElementById('Confirmation').addEventListener('change', Confirm, false);
}
function Confirm(){
var Confirmation=document.getElementById('Confirmation').checked;
var Message;
if(Confirmation){
Message="Confirmed";
}else{
Message="Not Confirmed"
}
document.getElementById('Result').innerHTML=Message;
}
<input type="checkbox" id="Confirmation" />
<span id="Result">Not Confirmed</span>
If you have any questions about the above source code please leave a ment below and I will get back to you as soon as possible.
The .checked property of a checkbox DOM element will tell give you the checked state of the element.
<input id="chktype" type="checkbox" class="chkone"><br>
if(document.getElementById('chktype').checked) {
alert('Checked');
} else {
alert('Not Checked');
}
Maybe:
$('.yourcheckbox').click(function() {
if( $('.yourcheckbox').is(":checked") ) {
do stuff
} else {
do other stuff
}
});
You can do it by using jQuery. Include the jQuery file in your head section:
<script src="//code.jquery./jquery-1.11.3.min.js"></script>
<?php
if($params['status'] == "2"){ ?>
<div class="pull-right" id="confirm-ship">
<input type="checkbox" class="chkone"><br>
<span></span>
</div>
<?php }
?>
<script>
$('.chkone').change(function(){
if($(this).prop('checked')==true)
{
$('span').html('Confirmed');
}
else
{
$('span').html('Not Confirmed');
}
});
</script>
Just change your code :
<div class="pull-right" id="confirm-ship">
<input type="checkbox" class="chkone" id="chkone"><br>
Use javascript :
$('.chkone').click(function(){
if($(this).is(':checked'))
{
//if checked do something
}
else
{
}
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745083194a4610249.html
评论列表(0条)