Settings>HTML:selectrow:function CallAjax(){jQuery(document).ready(function (){jQuery("input").click(function (e) {var idClicked=e.target.id;alert(idClicked);});});}Please have a look on the screenshot and my backup files.Thank in advance for you help.Bertrand"> Strange behaviour on Click Event in CCv5 listing - Forums

Forums

Strange behaviour on Click Event in CCv5 listing

bcouvin 21 Dec, 2015
Hello,

I found something strange.
I add on column for holding buttons in CCv5. To make a test, I make a message alert to send me the id of the button I clicked.
For the first click on the button, I have no message. The second click, I have a 2 messages.Those show me the button id. The third click on the button I have 3 messages showing me the button id. The fourth , 4 messages etc...


Here my code in javascript that I put in In Front List>Settings>HTML:
<script>
function CallAjax(){
	jQuery(document).ready(function (){
		jQuery("input").click(function (e) {
			var idClicked = e.target.id;
			alert(idClicked);
		});
	});
}
</script>


In Front List>Settings>HTML:
selectrow:<input type="button" id="button_PTO_{PTO.id}" onclick="CallAjax()" value="{PTO.id}"><script>function CallAjax(){jQuery(document).ready(function (){jQuery("input").click(function (e) {var idClicked=e.target.id;alert(idClicked);});});}</script>


Please have a look on the screenshot and my backup files.

Thank in advance for you help.

Bertrand
GreyHead 21 Dec, 2015
Answer
1 Likes
Hi bertrand,

I can see a couple of problems here; one is that if you add the JavaScript in the HTML box then it will be repeated once for each row in the listing which will probably lead to some weird results.

You also have a roundabout way of getting the id.

Please try this, or something like it. In the HTML box:
selectrow:<input type="button" id="button_PTO_{PTO.id}" onclick="CallAjax({PTO.id})" value="{PTO.id}" />


In the Header box you can add the JavaScript so that it is only there once
<script>
function CallAjax(id){
  alert(id);
}
</script>

Bob
This topic is locked and no more replies can be posted.