0

我正在尝试在此网站http://homepage.ntlworld.com/kayseycarvey/jss3p11.html上遵循本教程指南?

但是,我在这样做时遇到了一些困难。即使我做了完全相同的事情。如果您知道,请指导我。这是我所做的:

<html>
    <script>
        function GetSelectedItem() {

            chosen = ""
            len = document.f1.r1.length

            for (i = 0; i <len; i++) {
                if (document.f1.r1[i].checked) {
                    chosen = document.f1.r1[i].value
                }
            }

            if (chosen == "") {
                alert("No Location Chosen")
            }
            else {
                alert(chosen) 
            }
        }
    </script>

    <body>
        <form name="f1">
        <Input type = radio Name = r1 Value = "NE">North East
        <Input type = radio Name = r1 Value = "NW">North West
        <Input type = radio Name = r1 Value = "SE">South East
        <Input type = radio Name = r1 Value = "SW">South West
        <Input type = radio Name = r1 Value = "midlands">Midlands
        </form>


    </body></script>
</html>

附带说明一下,我是否必须对表单执行任何操作才能触发函数 GetSelectedItem ?提前致谢 !

4

4 回答 4

0

尝试这个

<input type="radio" onclick="autosubmit(this.value)" value="NE" name="r1">
<script type="text/javascript">
function autosubmit(value) {
window.location='update.php?radiovalue='+value;
}
</script>

更新.php

$rbtn=$_GET['radiovalue'];

//here your update query 
于 2013-09-06T07:18:40.793 回答
0

在单选按钮的 onchange 事件上添加 GetSelectedItem () 函数

     <input type="radio" onclick="GetSelectedItem()" value="NE" name="r1">
于 2013-09-06T06:58:46.520 回答
0

添加onsubmit="javascript:GetSelectedItem();"到您的form标签。

于 2013-09-06T06:56:56.410 回答
0
window.addEventListener('load', function () {
for (var i = 0; i < document.f1.r1.length; i++) {
    document.f1.r1[i].addEventListener("click", GetSelectedItem);
}
}, false);

function GetSelectedItem() {
alert(this.value);
}

http://jsfiddle.net/udSbL/2/

于 2013-09-06T07:05:23.087 回答