2

I am working on MVC project and I am running into an error when I am trying to open a Bootstrap modal.

The error message I am getting is:

Uncaught SyntaxError: missing ) after argument list

This is the button with the OnClick call:

<button id="btnVenueDelete" onclick="DeleteModal(@item.VenueName, @item.VenueID);" class="btn btn-sm btn-info">Delete</button>

This is the JavaScript function:

function DeleteModal(name, id) {
        console.log(Name);
        console.log(ID);

        txtModal.innerText = "Delete" + Name;
        $("#VenueModal").modal();
    }

I think the problem is due to something in the button as I am not seeing the console logs in the developer console.

0

1 Answer 1

4

Looks like item.VenueName is some string value. In that case, make sure to wrap the parameters in quotes.

<button id="btnVenueDelete" 
     onclick="DeleteModal('@item.VenueName', '@item.VenueID');" 
     class="btn btn-sm btn-info">Delete</button>

Now your code will not break even if the VenueName value is a string with space in it (Ex : "Ann Arbor")

I also assumes that txtModal inside the method is already defined somewhere before using it.

Also, javascript is case sensitive. so make sure you use the correct casing in the variable/argument names.

    function DeleteModal(name, id) {
        console.log(name);
        console.log(id);
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Yes I defined the modal and your solution worked perfectly thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.