Hi all. I need JavaScript to validate that atleast one checkbox has been checked in a form before the record(s) can be deleted.
- I have an <asp:button id="btnDelete". ..> and the checkbox is created via grdData_ItemDat aBound with id="chkRecordId ":
As advised in another forum, I have the following JS code:
It is still unable to work though, after calling the function via btnDelete.
Error has something to do with the array String.
Please advise, thanks.
- I have an <asp:button id="btnDelete". ..> and the checkbox is created via grdData_ItemDat aBound with id="chkRecordId ":
Code:
Protected Sub grdData_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdData.ItemDataBound If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then e.Item.Cells(1).Text = "<input type='checkbox' name='chkRecordId' value='" & e.Item.Cells(0).Text & "'/>" End If End Sub
Code:
<script language="javascript" event="onclick" for="btnDelete"> function validateCheckboxes() { var blnAllOkay = new Boolean(true); var strMessage = new String(""); var checkboxes = document.getElementsByName("chkRecordId"); for (var i = 0; i < checkboxes.lengths; i++) { if (checkboxes[i].checked == false) { strMessage += "<li>Please select minimum one competition category record to delete<br>"; blnAllOkay = false; } } if (blnAllOkay != true) { window.event.returnValue=false; lblMessage.innerHTML = strMessage; } } </script>
Error has something to do with the array String.
Please advise, thanks.
Comment