2

I want to call the function DeleteRow and EditRow on click of Delete Button and Edit Buttton.

<button style="margin-right: 5px;" type='button' onclick='return EditRow(@i)' id='@editrow' class='btn btn-primary btn-sm pull-right'><i class='glyphicon glyphicon-edit'></i>  </button>

<button style="margin-right:5px;" type='button' onclick='return DeleteRow(@i)' id='' class='btn btn-danger btn-sm pull-right'><i class='fa fa-times-circle'></i>  </button>

I have also made functions on my JavaScript file but I am getting this "undefined Error function error".

JavaScript Function here

<script type="text/javascript">
function DeleteRow(id) {
debugger 
//logic here
return false;
}

function EditRow(id) {
//logic here
return false;
}
</script>

I have got similar error before but at that time I only changed the function name in onClick at html and changed the function name at JavaScript but now no matters what I rename the function, I am getting the same error.

Can anyone explain why I am getting this error

0

1 Answer 1

1

Your code works if you make sure that your JS is defined before your buttons (or as long as you use some DOM ready event).

Also, make sure @i renders the right value. I don't recognize this pattern...

function DeleteRow(id) {
console.log('Delete ' + id);
return false;
}

function EditRow(id) {
console.log('Edit ' + id)
return false;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>

<button type='button' onclick='return EditRow(1)' id='@editrow' class='btn btn-primary btn-sm'><i class='glyphicon glyphicon-edit'></i>  </button>

<button type='button' onclick='return DeleteRow(1)' id='' class='btn btn-danger btn-sm'><i class='fa fa-times-circle'></i>  </button>

Sign up to request clarification or add additional context in comments.

2 Comments

@i renders a value. I didn't put the whole code because it would be so messy.
@i renders a value and function is also defined, it was working fine some times ago but now I am getting this function is not defined error message at console. Is it because it is getting conflict with other functions from other other JavaScript file on same project but no matter what I name my function I am getting same error. I have also faced this problem before but at that time just changing the name of function worked for me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.