PNS
PNS

Reputation: 770

Html radiobuttons

pretty new to HTML and I was wondering why this snippet of code doesn't work?

<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    <div style="font-family: Consolas;">
        <h1>This is a survey regarding *</h1>
        <form name="firstQuestion" method="get" action="">
            <input type="radio" name="q1" value="1" id="num1">I think its 1<br>
            <input type="radio" name="q1" value="2" id="num2">I think its 2<br>
            <input type="radio" name="q1" value="3" id="num3">I think its 3<br>
            <input type="radio" name="q1" value="4" id="num4">I think its 4<br>
            <input style="position: absolute; bottom: 10px; right: 10px" type="button" value="proceed" onclick="alert('Checked value is: '+getCheckedValue(document.forms['firstQuestion'].elements['q1']))"> 
        </form>
    </div>
</body>

The problem is that when I press the proceed button nothing happens whereas it is supposed to return the selected radio button as you can see.

Also now I'm at it, does anyone know how to add for example an extra textfield between option 3 and 4 if possibility 3 is chosen? by default and if not 3 is chosen the textfield shouldnt be visible.

Upvotes: 0

Views: 212

Answers (2)

scessor
scessor

Reputation: 16125

The button handler is calling a javascript function called getCheckedValue, but you haven't defined this.

=== UPDATE ===

<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
        function getCheckedValue(oElements) {
            // TODO: put in the function body here
        }
    <script>
</head>

Upvotes: 2

gigaSproule
gigaSproule

Reputation: 97

From what I gather from your question is that you are attempting to learn HTML, but don't know that you are in fact trying to use JavaScript to find the value.

If you are using a tutorial of some kind, you need to see where getCheckedValue is being defined and use that.

If you are not using a tutorial, I would recommend learning how to use JavaScript.

I find W3Schools is a good source for this.

Upvotes: 0

Related Questions