Mega Code Archive

 
Categories / JavaScript DHTML / Form Control
 

Checkbox in a form

<html> <head> <script type="text/javascript">     function check(){         coffee=document.forms[0].coffee         answer=document.forms[0].answer         txt=""         for (i=0;i<coffee.length;++ i){             if (coffee[i].checked){                 txt=txt + coffee[i].value + " "             }         }         answer.value="You ordered a coffee with " + txt     } </script> </head> <body> <form> How would you like your coffee?<br> <input type="checkbox" name="coffee" value="cream">With cream<br> <input type="checkbox" name="coffee" value="sugar">With sugar<br> <br> <input type="button" name="test" onclick="check()" value="Send order"> <br> <input type="text" name="answer" size="50"> </form> </body> </html>