Javascript examples for DOM HTML Element:Input Radio
Input Radio checked Property - Get check state for Several radio buttons in a form
<!DOCTYPE html> <html> <body> <p>Please choose the following:</p> <form action="#"> <input type="radio" name="coffee" value="cream">cream<br> <input type="radio" name="coffee" value="sugar">sugar<br> <br> <input type="button" onclick="myFunction()" value="Send order"> <br><br> <input type="text" id="order" size="50"> <input type="submit" value="Submit"> </form>// ww w.java 2s . co m <script> function myFunction() { var coffee = document.forms[0]; var txt = ""; var i; for (i = 0; i < coffee.length; i++) { if (coffee[i].checked) { txt = txt + coffee[i].value + " "; } } document.getElementById("order").value = "You ordered a coffee with: " + txt; } </script> </body> </html>