so i need to make validation for a form. the form need to have the value of 1 – 6 and there cannot be a duplicate.
so i make a temporary variable to record all the data kind of like this
let temporary = []
temporary[document.getElementById('needs_1').value-1] = 'needs 1';
temporary[document.getElementById('needs_2').value-1] = 'needs 2';
temporary[document.getElementById('needs_3').value-1] = 'needs 3';
temporary[document.getElementById('needs_4').value-1] = 'needs 4';
temporary[document.getElementById('needs_5').value-1] = 'needs 5';
temporary[document.getElementById('needs_6').value-1] = 'needs 6';
to validate it i put a condition with the length of the array is equal to 6. that will validate the 1-6 value needed. but it cannot validate duplicate number. because if there is skipped number lets say 1,5,6 if i check the length of temporary variable it still result in 6
2
Answers
You can try the following way:
If you prefer shorter solution:
If my thinking is right and you just want to iterate through your form then it will be much easier to use jQuery for that because with it you will be able to perform your operation more easily on your form.
if you have a html form described by @Mamun then with jQuery you can do somrthing like this: