input - Display random text based on checkbox selection (javascript) -


i'm getting grips javascript , need following:

have 4 checkboxes text "red, blue, yellow, green". when user clicks button, 1 of colours display randomly text.

any suggestions how javascript?

i believe trying do:

http://jsfiddle.net/derekl/qggws/

*i using jquery here explanatory purposes. convert pure javascript if want to.

$("button").click(function(){     $colors = $("input:checked");       //get checkboxes checked     if( $colors.length != 0){           //at least 1 checkbox has checked         var index = math.floor(math.random()*$colors.length); //generate ran. num         $("span").html($colors[index].value);                 //show value     }else{         alert("choose color!");       //tell user check @ least 1 box     }     }); 

one of randomly chosen color list of checked boxes show click on button.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -