ho trovato questo script che funziona bene
ma avrei bisogno di generalizzarla specificando come argomenti il nome del form e dei radio input
ho provato aggiungendo gli argomenti e sostituendoli nella funzione al posto di myform e sports ma non funge![]()
codice:<html> <head> <script type="text/javascript"> <!-- function vote() { var t="Your favourite sport is: " for (i=0; i<document.myform.sports.length; i++) { if (document.myform.sports[i].checked==true) { t =t +document.myform.sports[i].value } } if (t=="Your favourite sport is: ") { document.getElementById("txt").value="Choose a sport" } else { document.getElementById("txt").value=t } } --> </script> </head> <body> Vote for your favourite sport: <form name="myform"> <input type="radio" name="sports" value="Fotball" />Football <input type="radio" name="sports" value="Hockey" />Hockey <input type="radio" name="sports" value="F1" />F1 <input type="radio" name="sports" value="Basketball" />Bascketball <input type="radio" name="sports" value="Tennis" />Tennis <input type="radio" name="sports" value="Golf" />Golf <input type="button" value="VOTE" onClick="vote()" /> <input type="text" id="txt" /> </form> </body> </html>

Rispondi quotando