Reading CheckBoxes and Radio Buttons
Input tags with the type attribute checkbox can be grouped like radio buttons so that several checkboxes have the same name. However, any number of checkboxes can be selected by the user. Working with checkboxes in JavaScript is similar to but not exactly the same as working with radio buttons. Here is a short example that demonstrates getting values from checkboxes and radio buttons in the same form:
Music Survey
I enjoy: Classical Chamber Jazz Rock Punk Favourite Performer:Aitken Coltrane Julliard Kronos Waits
Getting all the values
A series of checkboxes with the same name are reflected as an array of checkbox objects. In this example each check box input tag is named Music
but has a different value. Since there are identically named input tags of the same type, an array of checkbox objects named Music
is created. When the button in this form is pressed, it passes a reference to the form to a function named, in this case, showBoxes(frm)
. The function loops through the checkbox array within the form. To access the check box array from the form reference it is only necessary to append the name of the checkboxes to the form reference:
frm.Music
For example to access the number of elements in the array:
frm.Music.length
or if the variable i
contains the index of one of the elements, here is how you would check to see if that element had been checked:
if (frm.Music[i].checked)
or get that element's value:
frm.Music[i].value
Since many values may be checked, this example gathers the values from each by appending each value on to the end of a string. Since the string is eventually displayed in an alert dialog each value is separated by a "\n", or new line character. In this case the string is named message
message = message + frm.Music[i].value + "\n"
Here is the complete page:
![]() |
<HTML> |
|
Reading CheckBoxes and Radio Buttons的更多相关文章
- playwright-python 处理Text input、Checkboxs 和 radio buttons(三)
Text input 输入框输入元素,直接用fill方法即可,支持 <input>,<textarea>, [contenteditable] 和<label>这些 ...
- [Angular2 Form] Create Radio Buttons for Angular 2 Forms
Using Radio Buttons in Angular 2 requires a basic understanding of forms as well as how their labels ...
- JSF 2 radio buttons example
In JSF, "h:selectOneRadio" tag is used to render a set of HTML input element of type " ...
- mfc Radio Buttons
添加单选按钮 关联变量 调试宏TRACE BOOL类型 一.添加一组单选按钮 二.添加第二组单选按钮 三.关联变量 四.单选按钮运用 void CMY_Dialog::OnBnClickedButto ...
- (转)Bootstrap 之 Metronic 模板的学习之路 - (4)源码分析之脚本部分
https://segmentfault.com/a/1190000006709967 上篇我们将 body 标签主体部分进行了简单总览,下面看看最后的脚本部门. 页面结尾部分(Javascripts ...
- selenium docs
Note to the Reader - Docs Being Revised for Selenium 2.0! Introduction Test Automation for Web Appli ...
- ASP.NET MVC异步上传文件
自己做的一个小dome.贴出来分享一下: 前端: <form id="formfile" method="post" enctype="mult ...
- Asp.net DropDownList 自定义样式(想怎么改就怎么改!)
最近在做一个asp.net的项目,需要对默认的dropdownlist样式进行美化,固有的dropdownlist的小箭头实在让人无法接受,于是开始在百度,google 上下求索,天不负有心人,终于找 ...
- Ajax.BeginForm 上传文件
在 Mvc 中上传文件时通常使用 Html.BeginForm 标签,同时对Form 添加属性 enctype = "multipart/form-data",前端代码如下: @H ...
随机推荐
- Chapter 2 -- Preconditions
Using Guava's precondition checking utilities, explained. explained Updated Apr 23, 2012 by wasserma ...
- CPLUSPLUS 获得 一个源文件的头文件依赖。即该文件所需要的所有头文件
核心命令:gcc -M *.h.*.cpp 转: 自动处理头文件的依赖关系 http://blog.csdn.net/su_ocean16/article/details/5374696 现在我们的M ...
- Altium Designer 13 插件安装
关键词:Altium Designer 13 :导入 Protel 99SE 很多人反应Altium Designer 13等版本无法 Protel 99SE的文件,实际上这是由于新的安装机制导致,新 ...
- 【StatLearn】统计学习中knn算法实验(2)
接着统计学习中knn算法实验(1)的内容 Problem: Explore the data before classification using summary statistics or vis ...
- CSS-返回顶部代码
现在的网站基本上都是长页面,多的有四五屏,少的话也有两三屏,页面太长有的时候为了提升用户体验,会在页面右边出现一个回到顶部的按钮,这样能快速回到顶部,以免在滑动页面出现视觉屏幕,回到顶部一般有四种方式 ...
- HTML5读取本地文件
本文转自:转:http://hushicai.com/2014/03/29/html5-du-qu-ben-di-wen-jian.html感谢大神分享. 常见的语言比如php.shell等,是如何读 ...
- Java-Shiro(三):Shiro与Spring MVC集成
新建Java Daynamic Web项目 导入Spring.SpringMVC依赖包: 导入Spring & Spring MVC包(导入如下所有开发包): Spring AOP依赖扩展包: ...
- Java-JUC(八):使用wait,notify|notifyAll完成生产者消费者通信,虚假唤醒(Spurious Wakeups)问题出现场景,及问题解决方案。
模拟通过线程实现消费者和订阅者模式: 首先,定义一个店员:店员包含进货.卖货方法:其次,定义一个生产者,生产者负责给店员生产产品:再者,定义一个消费者,消费者负责从店员那里消费产品. 店员: /** ...
- HttpWebRequest抓取网页数据返回异常:远程服务器返回错误: (503) 服务器不可用
解决方法: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webURL); //声明一个H ...
- 清空npm缓存
nodejs 清空 npm 缓存 npm cache clean -f