使用JavaScript验证单选按钮[关闭]

i'm trying to follow this tutorial guide on this website http://homepage.ntlworld.com/kayseycarvey/jss3p11.html?

However, i met some difficultly when doing so. Even though i did the exact same thing. Please guide me if you know so. Here are what i did:

<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>

On a side note, do i have to do anything to the form in order to trigger the function GetSelectedItem ? Thanks in advance !

add GetSelectedItem ()function on onchange event of your radio button

     <input type="radio" onclick="GetSelectedItem()" value="NE" name="r1">

Add onsubmit="javascript:GetSelectedItem();" to your form tag.

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/

try this

<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>

update.php

$rbtn=$_GET['radiovalue'];

//here your update query