JSFiddle - React, Tailwind, and code Playground
by darkajax
HTML
<button id='btn_swap1'>SWAP1</button><br>
<button id='btn_swap2'>SWAP2</button><br>
<button id='btn_swap3'>SWAP3</button><br>
<input type='text' id='txt_id1' /><br>
<input type='text' id='txt_id2' />
JavaScript
//jQuery('#btn_swap').click(function () {
//jQuery('button[id^=btn_swap]').click(function () {
jQuery('#btn_swap1, #btn_swap2, #btn_swap3').click(function () {
var txt1 = jQuery('#txt_id1').val();
var txt2 = jQuery('#txt_id2').val();
var type = jQuery(this).attr('id');
if ( txt1 && txt2 ) {
if ( txt1 == txt2 ) {
alert('You can not swap the same agent');
} else {
swapAgents(type);
}
} else {
alert("You're missing an agent");
}
});
function swapAgents(type) {
switch(type) {
case 'btn_swap1': alert('Function 1 for swap_btn1 called');
break;
case 'btn_swap2': alert('Function 2 for swap_btn2 called now');
break;
case 'btn_swap3': alert('Function 1 for swap_btn1 called');
break;
default:
break;
}
}
/*
if (type == 'btn_swap1') { }
else if (type == 'btn_swap2') { }
else if (type == 'btn_swap3') {}
else {}
*/