Hello everyone
Below is a link to what I want to achieve. I want to display number of fields based on the number a user selects. I used JSfiffle to work and edit the code, the issue is how to move it to Shopify. I tried moving it to shopify but nothing happened. Below is the link to the code and how it the function works as well as the codes involved.
https://jsfiddle.net/iteire2/ym93bvwe/
HTML
[details=Show More]
Show More
Show More
Show More
Show More
Show More
Show More
[details=Show More]
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
Show More
JAVASCRIPT
Show More
@
$(“#seeAnotherField”).change(function() {
if ($(this).val() == “1”) {
$(‘#otherFieldDiv’).show();
$(‘#otherFieldDiv2’).hide();
$(‘#otherFieldDiv3’).hide();
$(‘#otherFieldDiv4’).hide();
$(‘#otherFieldDiv5’).hide();
$(‘#otherFieldDiv6’).hide();
$(‘#otherField’).attr(‘required’, ‘’);
$(‘#otherField’).attr(‘data-error’, ‘This field is required.’);
} else if ($(this).val() == “2”) {
$(‘#otherFieldDiv’).show();
$(‘#otherFieldDiv2’).show();
$(‘#otherFieldDiv3’).hide();
$(‘#otherFieldDiv4’).hide();
$(‘#otherFieldDiv5’).hide();
$(‘#otherFieldDiv6’).hide();
$(‘#otherField’).attr(‘required’, ‘’);
$(‘#otherField’).attr(‘data-error’, ‘This field is required.’);
} else if ($(this).val() == “3”) {
$(‘#otherFieldDiv’).show();
$(‘#otherFieldDiv2’).show();
$(‘#otherFieldDiv3’).show();
$(‘#otherFieldDiv4’).hide();
$(‘#otherFieldDiv5’).hide();
$(‘#otherFieldDiv6’).hide();
$(‘#otherField’).attr(‘required’, ‘’);
$(‘#otherField’).attr(‘data-error’, ‘This field is required.’);
} else if ($(this).val() == “4”) {
$(‘#otherFieldDiv’).show();
$(‘#otherFieldDiv2’).show();
$(‘#otherFieldDiv3’).show();
$(‘#otherFieldDiv4’).show();
$(‘#otherFieldDiv5’).hide();
$(‘#otherFieldDiv6’).hide();
$(‘#otherField’).attr(‘required’, ‘’);
$(‘#otherField’).attr(‘data-error’, ‘This field is required.’);
} else if ($(this).val() == “5”) {
$(‘#otherFieldDiv’).show();
$(‘#otherFieldDiv2’).show();
$(‘#otherFieldDiv3’).show();
$(‘#otherFieldDiv4’).show();
$(‘#otherFieldDiv5’).show();
$(‘#otherFieldDiv6’).hide();
$(‘#otherField’).attr(‘required’, ‘’);
$(‘#otherField’).attr(‘data-error’, ‘This field is required.’);
} else if ($(this).val() == “6”) {
$(‘#otherFieldDiv’).show();
$(‘#otherFieldDiv2’).show();
$(‘#otherFieldDiv3’).show();
$(‘#otherFieldDiv4’).show();
$(‘#otherFieldDiv5’).show();
$(‘#otherFieldDiv6’).show();
$(‘#otherField’).attr(‘required’, ‘’);
$(‘#otherField’).attr(‘data-error’, ‘This field is required.’);
} else {
$(‘#otherFieldDiv’).hide();
$(‘#otherFieldDiv2’).hide();
$(‘#otherFieldDiv3’).hide();
$(‘#otherFieldDiv4’).hide();
$(‘#otherFieldDiv5’).hide();
$(‘#otherFieldDiv6’).hide();
$(‘#otherField’).removeAttr(‘required’);
$(‘#otherField’).removeAttr(‘data-error’);
}
});
$(“#seeAnotherField”).trigger(“change”);
$(“#seeAnotherFieldGroup”).change(function() {
if ($(this).val() == “yes”) {
$(‘#otherFieldGroupDiv’).show();
$(‘#otherField1’).attr(‘required’, ‘’);
$(‘#otherField1’).attr(‘data-error’, ‘This field is required.’);
$(‘#otherField2’).attr(‘required’, ‘’);
$(‘#otherField2’).attr(‘data-error’, ‘This field is required.’);
} else {
$(‘#otherFieldGroupDiv’).hide();
$(‘#otherField1’).removeAttr(‘required’);
$(‘#otherField1’).removeAttr(‘data-error’);
$(‘#otherField2’).removeAttr(‘required’);
$(‘#otherField2’).removeAttr(‘data-error’);
}
});
$(“#seeAnotherFieldGroup”).trigger(“change”);
CSS
Show More
form {
Show More
max-width: 900px;
Show More
display: block;
Show More
margin: 0 auto;
Show More
}