I'm looking for a techniuqe similar to a switch function in PHP so I can use a single function for multiple named selectors. Additional code would be added based on which selector calls the function.
My example is a 'Save' button along a 'Save And Close' button where the latter has additional code to close an accordion.
If the 'Save' button is clicked it calls this:
$('form[name=experienceForm]').submit(function(eve) {
eve.preventDefault();
tinyMCE.triggerSave();
var FormData = $(this).serialize();
var requestThis = $(this);
var inputCom = $(this).find('input[name=inputCom]').val();
var inputTitle = $(this).find('input[name=inputTitle]').val();
$.ajax({
type : 'POST',
url : '<?php echo site_url('resume/update'); ?>',
data: FormData,
dataType: "html",
context : $(this),
success : function(msg){
requestThis.closest('.item').children('h3').children('a').text(inputCom+' : '+inputTitle);
if(msg != '') {
showNotice(msg);
}
},
error: function(msg){
alert('FAIL '+msg);
}
});
});
I would like the 'Save and Close' button to do the same as above with this added:
$('input[name=experienceClose]').click(function(eve) {
eve.preventDefault();
tinyMCE.triggerSave();
$(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().accordion({active:"false"});
});
closestinstead of a millionparent()calls.