留言板

aui checkBox Click Event

thumbnail
Alexis Araya,修改在9 年前。

aui checkBox Click Event

Junior Member 帖子: 37 加入日期: 13-10-8 最近的帖子
Hi there,

I'm trying to detect the onclick event for a checkbox using aui, but has not been able to.
Liferay 6.1 CE


<aui:input name="international" id="international" type="checkbox" value="international"></aui:input>




<aui:script use="aui-node">

 AUI().ready('aui-base','node', 'event',  function (A) {
    	
      A.one('#international').on('click',
      function() {
       	alert('demo');
      });
   
 });
</aui:script>   


The code does not work, the alert is never displayed

Thank you for your help
thumbnail
Pankaj Kathiriya,修改在9 年前。

RE: aui checkBox Click Event

Liferay Master 帖子: 722 加入日期: 10-8-5 最近的帖子
Hi Alexis,
try with code below.

A.one('#internationalCheckbox').on('click', function(){alert("clicked");});

aui checkbox elemennt adds Checkbox prefix to id.
thumbnail
Alexis Araya,修改在9 年前。

RE: aui checkBox Click Event

Junior Member 帖子: 37 加入日期: 13-10-8 最近的帖子
I tried, but I generate javascript error


Chrome error
Uncaught TypeError: Cannot read property 'on' of null

Firefox Error
TypeError: b.one(...) is null

any idea?

Tranks
thumbnail
Manali Lalaji,修改在9 年前。

RE: aui checkBox Click Event

Expert 帖子: 362 加入日期: 10-3-9 最近的帖子
Hi,

You can add Cssclass selector and trigger onChange event as below:

<aui:input name="international" id="international" type="checkbox" value="international" cssclass="test"></aui:input>


Can you try below?

A.one('.test .aui-field-input-choice:checkbox').on('change',function(){alert("test");});



HTH!
thumbnail
Pankaj Kathiriya,修改在9 年前。

RE: aui checkBox Click Event

Liferay Master 帖子: 722 加入日期: 10-8-5 最近的帖子
Sorry, forgot to mention. aui tags also append <portlet:namespace/> to it.

Try this:

A.one('#<portlet:namespace />internationalCheckbox').on('click', function(){alert("clicked");});
thumbnail
Alexis Araya,修改在9 年前。

RE: aui checkBox Click Event

Junior Member 帖子: 37 加入日期: 13-10-8 最近的帖子
Pankaj Kathiriya:
Sorry, forgot to mention. aui tags also append <portlet:namespace/> to it.

Try this:

A.one('#<portlet:namespace />internationalCheckbox').on('click', function(){alert("clicked");});



Thank you very much, now it works