


js method to obtain radio button value without submitting form_javascript skills
The example in this article describes the js method to obtain the radio button value without submitting the form. Share it with everyone for your reference. The details are as follows:
This is a special effect implemented by JS. It does not submit the form to obtain the relevant control values. As shown in this example, you can get the value of a radio button without submitting the form.
The screenshot of the running effect is as follows:
The online demo address is as follows:
http://demo.jb51.net/js/2015/js-alert-show-table-value-codes/
The specific code is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>不提交表单获取单选按钮的值</title> <style type="text/css"> <!-- .style1 {color: #FFFFFF} --> </style> <script type="text/javascript"> function getVal(){ var CardTypeValue; for (i=0;i<form1.CardType.length;i++){ if (form1.CardType[i].checked){ CardTypeValue=form1.CardType[i].value; break; //使用该语句可以减少不必要的循环次数 } } if(CardTypeValue=="身份证"){ if(form1.pcard.value.length!=15 && form1.pcard.value.length!=18){ alert("您输入的证件号码有误!");form1.CardType.focus();return; } }else{ if(CardTypeValue=="学生证"){ if(form1.pcard.value.length!=8 && form1.pcard.value.length!=12){ alert("您输入的证件号码有误!");form1.CardType.focus();return; } } } } </script> </head> <body> <table width="650" height="34" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#B3CAEE"> <tr class="font_white"> <td height="22" align="center"><span class="style1">====== 用户注册信息 ======</span></td> </tr> </table> <table width="650" height="205" border="0" align="center" cellpadding="-2" cellspacing="-2" class="tableBorder"> <tr valign="top"> <td height="171" colspan="3"><table width="100%" height="129" border="0" cellpadding="-2" cellspacing="-2"> <tr> <td valign="top"> <table width="100%" height="265" border="0" cellpadding="-2" cellspacing="-2" class="tableBorder_Top"> <tr> <td height="5"></td> </tr> <tr> <td width="195" height="263" valign="top"><table width="100%" border="0" cellspacing="-2" cellpadding="-2"> <tr> <td width="55%" height="82" align="center" class="word_grey"></td> <td width="45%" align="left" class="word_grey"><b>注册帮助</b></td> </tr> <tr> <td height="112" colspan="2" valign="top" class="word_grey"><ul> <li> 用户名:为用户登录留言簿的通行证,可使用英文字母、数字或英文字母、数字、下划线的组合,长度控制在3-20个字符之内。</li> <li>真实姓名: 请输入真实的姓名,该项为隐藏项,用户可以放心输入。</li> <li>Email:请填写有效的Email地址,以便与您联系。</li> </ul></td> </tr> <tr align="center"> <td colspan="2" valign="middle" class="word_grey"></td> </tr> </table></td> <td width="19" background="Images/line.gif"></td> <td width="436" valign="top"><br> <br> <table width="90%" border="0" align="center" cellpadding="-2" cellspacing="-2"> <tr> <td><form name="form1"> <table width="100%" border="0" cellspacing="-2" cellpadding="-2"> <tr> <td width="18%" height="30" align="center">用 户 名:</td> <td width="82%"><input name="UserName" type="text" id="UserName4" maxlength="20"> * </td> </tr> <tr> <td height="28" align="center">真实姓名:</td> <td height="28"><input name="TrueName" type="text" id="TrueName4" maxlength="10"> *</td> </tr> <tr> <td height="28" align="center">证件类型:</td> <td><input name="CardType" type="radio" class="noborder" value="身份证" checked> 身份证 <input name="CardType" type="radio" class="noborder" value="学生证"> 学生证</td> </tr> <tr> <td height="28" align="center">证件号码:</td> <td class="word_grey"><input name="pcard" type="text" id="Tel" onBlur="getVal()"></td> </tr> <tr> <td height="28" align="center">联系电话:</td> <td><input name="tel" type="text" id="Tel"></td> </tr> <tr> <td height="28" align="center" style="padding-left:10px">Email:</td> <td class="word_grey"><input name="Email" type="text" id="PWD224" size="35"> </td> </tr> <tr> <td height="28" align="center">个人主页:</td> <td class="word_grey"><input name="homepage" type="text" id="homepage" size="35"></td> </tr> <tr> <td height="34"> </td> <td class="word_grey"><input name="Button" type="button" class="btn_grey" value="确定保存"> <input name="Submit2" type="reset" class="btn_grey" value="重新填写"></td> </tr> </table> </form></td> </tr> </table></td></tr> <tr> <td height="5"></td> </tr> </table></td> </tr> </table></td> </tr> </table> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

How to use JS and Baidu Maps to implement the map heat map function Introduction: With the rapid development of the Internet and mobile devices, maps have become a common application scenario. As a visual display method, heat maps can help us understand the distribution of data more intuitively. This article will introduce how to use JS and Baidu Map API to implement the map heat map function, and provide specific code examples. Preparation work: Before starting, you need to prepare the following items: a Baidu developer account, create an application, and obtain the corresponding AP

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.
