Click here to Skip to main content
14,934,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When the user selects to delete a department or location, then the system checks against the database to see if that entry is used in other tables (ie personnel assigned to that department) and, if so, should prevent removal.

If it prevents removal I want to have a popup saying: "This department/location can't be removed."

At the moment it is only showing: "Removed" for both elements, the removed ones and the ones that are not being deleted.

How can I make two different responses, one for the removed and one for the non removed?

I have tried the below however it is showing an error on the HTML line 12 which is the css link and I am feeling a bit confused:

Uncaught SyntaxError: missing ) after argument list.

<link rel="stylesheet" type="text/css" href="css/style.css">


What I have tried:

JavaScript
function toggleConfirmDep(message, func) {
    
    if (!event) var event = window.event;
    event.cancelBubble = true;
    if (event.stopPropagation) event.stopPropagation();


    employeeID = $(event.target).closest(".buttons").siblings("form").find("#id").text();

    if ($('#confirmDep').css('display') == "none") {

        $('#confirmDep').show()
        $('#depQuestion').show()
        $('#depResponse').hide()

        let addOrRemove = capitalizeFirstLetter(message.split(" ")[0])
        addOrRemove == "Add" ? addOrRemove += "ed" : addOrRemove += "d"

        $('#depMessage').text(message)
        $('#depButton').attr('onClick', `
        
            ${func.toString()};
            $('#depQuestion').hide()
            $('#depResponse').show()

            if (event.cancelBubble == true) {
                
                $('#depResponseMessage').text('${addOrRemove}');

            } else if (event.cancelBubble == false) {
                                
                $('#depResponseMessage').text('This department can't be removed.');

            } else {

                $('#depResponseMessage').text('${addOrRemove}');

            }



            
            setTimeout(function(){
            
                $('#confirmDep').hide();
                
                $('#profilePage').hide();
                
                window. location. reload(1);
                
            }, 1500);
            
        `)

    } else {
        
        $('#confirmDep').css('display', 'none')

    }

}




HTML
<div class="modal" id="removeDepartmentOverlay">

			<div class="addDepLoc">

				<div class="row profileRow">

					<h3 style="display: inline">Department:</h3>
					<select id="removeDepartmentDepartment" style="display: inline; float: right;"></select>
				
				</div>
				
				<br>
				<br>

				<div class="row d-flex align-items-center justify-content-center pt-3" id="removeDepLocBtn">
				
					<div class="col d-flex justify-content-center">

						<button class="button buttonClose" style="display: inline; float: left;" onclick="toggleRemoveDepartment()"></button> 

					</div>

					<div class="col d-flex justify-content-center">

						<div class="btn btn-xs btn-primary5" id="confirmButton" style="display: inline; float: right;" onclick="toggleConfirmDep('Remove', 'removeDepartment()')">^__i class="fa fa-check-circle fa-xs" style="font-size: 1em" data-toggle="modal"></div>

					</div>

				</div>
				
			</div>

		</div>
Posted
Updated 1-Mar-21 6:52am
v3
Comments
Richard MacCutchan 1-Mar-21 11:55am
   
What is in the content of the message variable when this function is called?
farremireia 1-Mar-21 11:58am
   
I have updated the question with the HTML if it helps?
Richard MacCutchan 1-Mar-21 12:05pm
   
See below.

1 solution

You have an error in the following c ode:
JavaScript
if (event.cancelBubble = true) {
                       ^ this should be ==, two equal signs.
    $('#depResponseMessage').text('${addOrRemove}');

} else if (event.cancelBubble = false) {
                              ^ so should this
    $('#depResponseMessage').text('This department can't be removed.');

} else {

    $('#depResponseMessage').text('${addOrRemove}');

}
   
Comments
farremireia 1-Mar-21 12:33pm
   
It doesn't work I'm afraid, if I use this code the console tells me there is a syntax error but there is not:

Uncaught SyntaxError: missing ) after argument list
Richard MacCutchan 1-Mar-21 12:37pm
   
We cannot guess what code you have tried. Please use the Improve question link above, and show the code that you are using and explain which line causes the syntax error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900