Issue
I'm trying to make sure every field is required but this code only works on "input" tags but not on the select and textarea tags.
Any help will be appreciated. Thanks!
HERE IS MY BLADE
<div class="tab">
<div class="form-group mb-3">
<select name="currency" class="choices form-control" id="devise{{ Auth::user()->cred->id }}"
onchange="deviseSelect({{ Auth::user()->cred->id }})" required="true">
<option value="" selected disabled>choose</option>
<option value="USD">USD</option>
<option value="FC">FC</option>
</select>
</div>
</div>
HERE IS MY JAVASCRIPT FOR THE "SELECT" HTML TAG
<script>
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the current tab
function validateSelect()
{
// This function deals with validation of the form fields
var x,z, i, valid = true;
x = document.getElementsByClassName("tab");
z = x[currentTab].getElementsByTagName("select");
// A loop that checks every select field in the current tab:
for (i = 0; i < z.length; i++) {
var option = z.options[i];
// If a field is empty...
if (option.value == "") {
// add an "invalid" class to the field:
z[i].className += " required";
// and set the current valid status to false:
valid = false;
}
}
// If the valid status is true, mark the step as finished and valid:
if (valid) {
document.getElementsByClassName("step")[currentTab].className += " finish";
}
return valid; // return the valid status
}
</script>
Solution
I FOUND WHERE I'VE MISTAKEN
I just changed something inside the for loop and everything started working perfectly.
<script>
for (i = 0; i < z.length; i++) {
// If a field is empty...
if (z[i].value == "") {
// add an "invalid" class to the field:
z[i].className += " is-invalid";
// and set the current valid status to false:
valid = false;
}
}
</script>
Answered By - BMFA
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.