I'm having some strange problem with my JS program.
(我的JS程序遇到一些奇怪的问题。)
I had this working properly but for some reason it's no longer working. (我的工作正常,但由于某种原因,它不再工作。)
I just want to find the value of the radio button (which one is selected) and return it to a variable. (我只想查找单选按钮的值(已选中该按钮)并将其返回给变量。)
For some reason it keeps returning undefined
. (由于某种原因,它总是返回undefined
。)
Here is my code:
(这是我的代码:)
function findSelection(field) {
var test = 'document.theForm.' + field;
var sizes = test;
alert(sizes);
for (i=0; i < sizes.length; i++) {
if (sizes[i].checked==true) {
alert(sizes[i].value + ' you got a value');
return sizes[i].value;
}
}
}
submitForm
:
(submitForm
:)
function submitForm() {
var genderS = findSelection("genderS");
alert(genderS);
}
HTML:
(HTML:)
<form action="#n" name="theForm">
<label for="gender">Gender: </label>
<input type="radio" name="genderS" value="1" checked> Male
<input type="radio" name="genderS" value="0" > Female<br><br>
<a href="javascript: submitForm()">Search</A>
</form>
ask by mkyong translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…