[英]Is it possible to get the values of radio button in different pages?
I did not post all the html code but i do give an example HTML. 我没有发布所有的HTML代码,但我给出了一个示例HTML。
If i have 4 pages is it possible to get all the values of radio button that is checked per page. 如果我有4页,则可以获得每页检查的单选按钮的所有值。
PAGE 1 第1页
<table>
<tbody>
<tr class="choices1">
<td align="center"><input id="r1" name="radio" type="radio" value="Stop" /></td>
<td>Stop</td>
</tr>
<tr class="choices2">
<td align="center"><input id="r2" name="radio" type="radio" value="Go" /></td>
<td>Go</td>
</tr>
<tr class="choices1">
<td align="center"><input id="r3" name="radio" type="radio" value="Ready" /></td>
<td>Ready</td>
</tr>
<tr class="choices2">
<td align="center"><input id="r4" name="radio" type="radio" value="Fly" /></td>
<td>Fly</td>
</tr>
</tbody>
</table>
My Code 我的守则
// this is the code that i'm using to get the value of the radio button that is checked.
// this code is working for 1 page only.
function findSelection(field) {
var test = document.getElementsByName(field);
var q1 = 0, q2 = 0;
var score = 0;
for (i=0; i < test.length; i++) {
if (test[i].checked==true) {
return (test[i].value);
}
}
}
function submit() {
var choice = findSelection("radio");
alert(choice);
return false;
}
You can bind an onClick event to the input elements. 您可以将onClick事件绑定到输入元素。
<table>
<tbody>
<tr class="choices1">
<td align="center">
<input id="r1" name="radio" type="radio" value="Stop" onclick="myFunction(this);" />
</td>
<td>Stop</td>
</tr>
<tr class="choices2">
<td align="center">
<input id="r2" name="radio" type="radio" value="Go" onclick="myFunction(this);" />
</td>
<td>Go</td>
</tr>
<tr class="choices1">
<td align="center">
<input id="r3" name="radio" type="radio" value="Ready" onclick="myFunction(this);" />
</td>
<td>Ready</td>
</tr>
<tr class="choices2">
<td align="center">
<input id="r4" name="radio" type="radio" value="Fly" onclick="myFunction(this);" />
</td>
<td>Fly</td>
</tr>
</tbody>
The onclick function can call a function to alert the value. onclick函数可以调用函数来提醒值。
function myFunction(id) {
alert(id.value);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.