如果没有选中任何复选框,如何显示消息 [英] how to display message if none of the checkbox is selected

查看:114
本文介绍了如果没有选中任何复选框,如何显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在使用复选框从数据库中删除记录。仅表示将从复选框中选中的数据库中删除该记录。在删除记录之前,我显示一条消息你确定要删除所选记录吗?使用javascript.and当用户单击确定时,将删除记录。


这里的消息我希望它应该像你确定要删除5条记录吗?如果用户选择5条记录。那么我怎么能用javascript做这个呢。


如果用户没有选中任何复选框并点击删除按钮,那么它应该显示消息没有选择记录。请选择使用javascript,我怎样才能在javascript中执行此操作。


复选框的名称为chkdelete。

Hi

I am deleting records from database using checkbox. means only that record will be deleted from database which are selected in checkbox. and before deleting record I am displaying a message "Are you sure to delete the selected records" using javascript.and when user clicks OK, record is deleted.

Here in message I want it should like "Are you sure to delete 5 records" if user selects 5 records. So how can I do this using javascript.

And if user without selecting any checkbox and clicks Delete button then it should display message "no record is selected. please select" using javascript so how can I do this in javascript.

Name of the checkbox is chkdelete.

推荐答案

@mukeshrasm


您可以计算已选中复选框的数量。使用getElementsByName()来获取所有框并测试每个框的复选框 .checked属性。
@mukeshrasm
you can count the number of checked checkboxes. use getElementsByName() to get all boxes and test the checkbox.checked property for each one.


@Dormilich


如何计算已选中复选框的数量。
@Dormilich
How can I count the number of checked checkboxes.


@mukeshrasm


getElementsByName(" checkdelete")将为您提供所有复选框(作为数组*)。循环遍历此数组(使用for循环)并测试checked属性是否为true(选中)或false(未选中),如果为true,则递增计数器变量(对于选中的复选框)。


*它实际上是一个HTMLElementCollection,它是一个Object(具有数字属性)而不是一个Array。不同之处在于此对象不包含Array对象的大多数方法(如pop(),push(),shift(),...)。
@mukeshrasm
getElementsByName("checkdelete") will give you all the checkboxes (as array*). loop through this array (using for-loop) and test if the checked property is true (checked) or false (unchecked), if it is true, increment you counter variable (for checked checkboxes).

* it is actually a HTMLElementCollection, which is an Object (with numerical properties) rather than an Array. The difference is that this object doesn''t contain most methods of the Array object (like pop(), push(), shift(), ...).


这篇关于如果没有选中任何复选框,如何显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆