hepzibah
hepzibah

Reputation: 45

conditioning check boxes and radio buttons in flask

I have 3 basic html pages created in flask. I created a simple questionnaire having check boxes and radio buttons as shown in the image below. I want to be able to add a condition such that if e.g(male + musical instruments + football + volleyball)then sports.html and entertainment.html should be suggested. Similarly if (female + music + volleyball) then science.html and entertainment.html should be displayed. I just want to be able to recommend pages based on the questions answered. Thanksquestionaire

Upvotes: 0

Views: 805

Answers (1)

calthoff
calthoff

Reputation: 386

Here is a Javascript/jQuery script that will alert "The best choices are sports.html and entertainment.html" if male + musical instruments + football + volleyball is selected and "science.html and entertainment.html are the best choices" if female + music + volleyball are selected.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script>
function suggest(){



if ( $("#male").is(':checked') && $('#mi').is(':checked')  && $('#football').is(':checked') && $('#volleyball').is(':checked') ) {
    alert("The best choices are sports.html and entertainment.html");
    }


else if ($("#female").is(':checked')  && $("#music").is(':checked')  && $("#volleyball").is(':checked') ) {
    alert("science.html and entertainment.html are the best choices");
    }
}
</script>

<input type="radio" id = "male" name ="sex" value="male">Male<br>
<input type="radio" id = "female" name = "sex" value="female">Female<br>

<input type="checkbox" id = "mi"> Musical Instruments<br>
<input type="checkbox" id = "football"> Football<br>
<input type="checkbox" id = "volleyball"> Volleyball<br>
<input type="checkbox" id = "music"> Music<br>
<button type="button" onclick = "suggest()">Submit</button>

Upvotes: 1

Related Questions