I have a html button that should be firing javascript on button click. It recognizes the button click and display the confirm alert but does not continue on and post the console.logs or go to into the ajax method.
Here is the javascipt function:
$('.Delete')
.click(function() {
return confirm("Are you sure you'd like to delete this entry?"
if(return = true)
{
var parent = $(this).parent().prev();
var tr = $(this).closest('tr');
var ValNode = tr.find(".typeText").first();
var AddrNode = parent.children(".AddrText").first();
var Val = ValNode.val();
var addr = addrNode.val();
console.log(Val);
console.log(addr);
var item = { Value: Val, Address: addr }
deleteItem(userID, item);
}
});
This is the html elements I think it may have to do with the relationship of the button to the elements its calling. I have them as cousins.
<asp:ListView runat="server" id="ListView1" >
<LayoutTemplate>
<thead>
<tr>
<th>
<a href="#">Type</a>
</th>
<th>
<a href="#">Address</a>
</th>
</tr>
</thead>
<tbody>
<tr id="itemPlaceholder" runat="server" />
</tbody>
<tfoot>
</tfoot>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<input type="text" id="Type" class="TypeText " value="<%# Eval("Type")%>" />
<input type="text" id="Addr" class="AddrText " value="<%# Eval("Address")%>" />
</td>
<td>
<input type="button" id="btn_update" class="Update" value="Update" />
<input type="button" id="btn_delete" class="Delete" value="Delete" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
1.
returnis a reserved word in JavaScript. It is used to specify what a function returns to the caller. Do not use it for variable names.Change
return confirm("Are you sure you'd like to delete this entry?"to
var result = confirm("Are you sure you'd like to delete this entry?");2.Your
ifcondition check is incorrectChange
if(return = true)to
if(result == true)