I'm currently updating an old web application using jQuery.
Within the form, there are 40 buttons that trigger a confirmation prompt using javascript confirm. I aim to replace these with jquery modal dialogues.
While I've successfully implemented this for a few buttons, having to do it individually for all 40 seems tedious. The only variation between them is the javascript function called when 'Yes' is clicked.
Any ideas on how to streamline this process?
Sample code for button:
$("#confirm1dialogTitle").html("Approve?");
$("#confirm1dialogText").html("Do you want to approve this request?");
$('#confirm1dialog').dialog('open');
Inline script:
<script type="text/javascript">
$(function() {
$("#confirm1dialog").dialog({
bgiframe: true,
autoOpen: false,
width: 350,
height: 350,
modal: true,
buttons: {
'Yes': function() {
window.document.forms[0].FDDStatus.value = "Approved";
window.document.forms[0].DivisionApproval.value = "Yes";
window.document.forms[0].setApprovalFields();
},
'No': function() {
$(this).dialog('close');
}
}
});
});
</script>
Inline HTML:
<div id="confirm1dialog" title="<span id='Title'>Title</span>">
<div id="users-contain" class="ui-widget">
<form>
<span id="confirm1Text"></span>
</form>
</div>
</div>