I want create a form. The form has 15 questions. Every questions has 4 answers. Visitors can select minimum 1 and maximum 2 answers for a question. It's okay, i do it.
If visitor select 1 answer, i can read value of the selected answer. If visitor select 2 answers, i can read values too. But i need know which is first selected and which is second selected. Because; if visitor select 3rd answer, then selected 1st answer;
- I need get the value and i need get 2 point for first selected answer
- I need get the value and i need get 1 point for 2nd selected answer
In my example 3rd answer's value is green and 1st answer's value is red. So i need get "green-2" value from the 3rd answer and get "red-1" value from the 1st answer.
How can i do that?
My code is here :
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Personal Information</title>
<script src="http://ift.tt/1LdO4RA"></script>
</head>
<body>
<form>
<p><strong>How are you today?</strong></p>
<input type="checkbox" class="limited" id="q1a" value="red">Perfect<br>
<input type="checkbox" class="limited" id="q1b" value="yellow">Good<br>
<input type="checkbox" class="limited" id="q1c" value="green">Normal<br>
<input type="checkbox" class="limited" id="q1d" value="blue">Bad<br>
</form>
</body>
<script>
$(document).ready(function() {
var checkboxes = $('.limited');
checkboxes.on('click', function() {
var limit = 2;
var selected = checkboxes.filter(":checked").length;
if (selected > limit) {
alert("You can select maximum " + limit + " answer");
$(this).prop('checked', false);
}
});
});
</script>
</html>
Aucun commentaire:
Enregistrer un commentaire