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 ...
随机推荐
- hyper-v 尝试更改 状态时 应用程序遇到错误 无法初始化
刚还原了一个问题,现在 又来一个: 让我崩溃的微软 hyper-v.这次错误 提示也没了. http://social.technet.microsoft.com/Forums/de-DE/751b2 ...
- ASP,ASP.net,JSP语法、内置对象对比
1 各自的HelloWord版本 1.1 ASP <% Response.Write("hello asp") %> 文件名为test.asp. 1.2 ASP.ne ...
- Construct Binary Tree from Preorder and Inorder Traversal leetcode java
题目: Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume ...
- Limu:有关JavaScript的那些值得一看的书
来源&作者:Limu 又好久没写东西了 ,写上一篇的时候还以为接下来的工作会轻松一些 ,结果未从我所愿呐 ,又是一阵忙碌.而这段时间穿插着做了很多12年淘宝校园招聘的前端面试 ,很多同学都有问 ...
- Python3爬虫:利用Fidder抓取手机APP的数据
1.什么是Fiddler? Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,设置断点,查看所有的“进出”Fiddler的数据(指cookie,ht ...
- 【Spark】SparkStreaming-Kafka-Redis-集成-基础参考资料
SparkStreaming-Kafka-Redis-集成-基础参考资料 Overview - Spark 2.2.0 Documentation Spark Streaming + Kafka In ...
- 详细解读简单的lstm的实例
http://blog.csdn.net/zjm750617105/article/details/51321889 本文是初学keras这两天来,自己仿照addition_rnn.py,写的一个实例 ...
- Structured Streaming编程向导
简介 Structured Streaming is a scalable and fault-tolerant stream processing engine built on the Spark ...
- 模拟日历计算 poj1008
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 69932 Accepted: 21524 D ...
- MFC自定义控件如何向父窗口发送自定义消息
自定义了一个控件 class CHtmlEditCtrlEx : public CHtmlEditCtrl 想在这个控件接收到Ctrl+V键盘消息的时候,向该控件所在的窗口发送一个自定义消息.具体 ...