i tried few days to make this code working but today i got the idea to ask some help. Here is the problem: when i try to send the value of my input fields to my params variable, i just get nothing, an empty value. However when i remove my validation function,
$(document).input.hasAttribute('required').each(function () {
if ($(this).val() == "") {
alert('Please fill all the fields');
}
});
all the parameters are in my url : ?rpt=123456&etc...etc...
Do you know why i loose my variable value on the way? If yes how to solve this?
Thanks for the help
jQuery(document).ready(function() {
jQuery("#vb_report_date").datepicker({
format: 'dd/mm/yyyy',
autoHide: true
});
jQuery("#vb_verify_button").click(function() {
check_required_inputs(true);
});
});
function check_required_inputs(hasbeenSubmited) {
var params = "";
if (hasbeenSubmited) {
$(document).input.hasAttribute('required').each(function() {
if ($(this).val() == "") {
alert('Please fill all the fields');
}
});
params = "?rpt=" + jQuery("#vb_report_no").val() + "&d=" + jQuery("#vb_report_date").val() + "&pin=" + jQuery("#vb_verif_pin").val();
}
window.location.href = "verify-reports.php" + params;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<body>
<form id="requiredform" class="verify-box">
<input type="text" id="vb_report_no" placeholder="Report Number" size="22" data-error="This field is required." class="" required>
<input type="text" id="vb_report_date" placeholder="Date of Issue" size="12" class="hasDatepicker" data-error="This field is required." required>
<input type="text" id="vb_verif_pin" placeholder="Verification PIN" size="22">
<input type="submit" value="Verify" id="vb_verify_button">
</form>
</body>
</html>