最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Prevent calling onchange event when checkbox value changes - Stack Overflow

programmeradmin2浏览0评论

I would like to prevent triggering the onchange event of selectbooleancheckbox when its value is toggled in toggleBillableChkBox method.

<p:selectBooleanCheckbox value="#{myBean.billableBoolean}" widgetVar="billableEditVar"
    id="billableEdit" onchange="showBillableForEdit(this)">
</p:selectBooleanCheckbox>

function showBillableForEdit(obj){
     if(obj.checked){
        confirmBillableYesEdit.show();
    } else{
        confirmBillableNoEdit.show();
    }
}


<p:confirmDialog id="confirmBYesEditId" header="Please Confirm" severity="alert" visible="false"      
    widgetVar="confirmBillableYesEdit" 
    message="edit Are you sure  you want to invoice this service ?" >
    <p:mandButton value="Yes" onplete="confirmBillableYesEdit.hide();" global="false" >
    </p:mandButton>

    <p:mandButton value="No"   onclick="toggleBillableChkBox();"
        onplete="confirmBillableYesEdit.hide();">
    </p:mandButton>
</p:confirmDialog>


function toggleBillableChkBox() {
    billableEditVar.toggle();
}

I would like to prevent triggering the onchange event of selectbooleancheckbox when its value is toggled in toggleBillableChkBox method.

<p:selectBooleanCheckbox value="#{myBean.billableBoolean}" widgetVar="billableEditVar"
    id="billableEdit" onchange="showBillableForEdit(this)">
</p:selectBooleanCheckbox>

function showBillableForEdit(obj){
     if(obj.checked){
        confirmBillableYesEdit.show();
    } else{
        confirmBillableNoEdit.show();
    }
}


<p:confirmDialog id="confirmBYesEditId" header="Please Confirm" severity="alert" visible="false"      
    widgetVar="confirmBillableYesEdit" 
    message="edit Are you sure  you want to invoice this service ?" >
    <p:mandButton value="Yes" onplete="confirmBillableYesEdit.hide();" global="false" >
    </p:mandButton>

    <p:mandButton value="No"   onclick="toggleBillableChkBox();"
        onplete="confirmBillableYesEdit.hide();">
    </p:mandButton>
</p:confirmDialog>


function toggleBillableChkBox() {
    billableEditVar.toggle();
}
Share Improve this question asked Nov 11, 2014 at 15:41 meheremehere 1,5565 gold badges29 silver badges53 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

You can't prevent the event from firing that I know of but you can stop it from doing anything with this code. (this replaces your onclick) in a script tag:

$('#billableEdit').on('change', function( evt ) {
  evt.preventDefault();
  evt.stopPropagation();
  billableEditVar.toggle();
});

return false didnot work for me..so i just cleared the onchange of the element just before toggling.

function toggleBillableChkBox() {
   document.getElementById('billableEdit_input').onchange = "";        
   billableEditVar.toggle();
}
发布评论

评论列表(0)

  1. 暂无评论