Question
Some required attributes are not validated while using form and javascript
I'm using a form for issues with mandatory fields but some aren't taken into account.
Of the 6 required input
blocks only 4 are correctly validated when you try to submit the form. The 'IVR status' and the 'Description' blocks are not validated.
I'm drawing a blank what I have missed in the code that exclude these blocks from being validated.
function generateEmail(event) {
event.preventDefault();
var emailTo = "a@b.c";
var emailCC = "d@b.c";
var emailBCC = "e@b.c";
var emailSubject = "WEBFORM: " + $("#subject").val();
var emailBody = "Reporter: " + $("#reporter").val() + "%0A%0AThe issue occured on: " + $("#issueDT").val() +
"%0A%0ACustomer Account Data: " + "%0A Account: " + $("#accnt_1").val() + "%0A%0ACustomer Account Data: " + "%0A Account: " + $("#accnt_2").val() + "%0A Agreement: " + $("#agree_1").val() + "%0A Agreement: " + $("#agree_2").val() + "%0A Agreement: " + $("#agree_3").val() + "%0A%0AIVR Status: " + $("#ivrState").val() + "%0A%0ADescription: " + $("#descript").val()
location.href = "mailto:" + emailTo + "?"
+ ( emailCC ? "cc=" + emailCC : "")
+ ( emailBCC ? "&bcc=" + emailBCC : "")
+ ( emailSubject ? "&subject=" + emailSubject : "")
+ ( emailBody ? "&body=" + emailBody : "");
}
function reloadPage() {
location.reload();
}
.container {
width: 800px;
border: 2px solid black;
padding: 15px;
}
.control {
color: blue;
}
h1 {
color: green;
}
h2 {
color: red;
}
<div class="container">
<h1>Report your issue</h1>
</br>
</br>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" class="info" onsubmit="generateEmail(event)">
Email Subject: </br><input name="subject" placeholder="Subject 20 characters min" id="subject" type="text" size="100" minlength="20" required /></br>
Reporter Name: </br><input name="reporter" placeholder="Reporter name" id="reporter" type="text" size="100" maxlength="75" required /></br>
Date & time the issue occured: </br><input name="issueDT" id="issueDT" type="datetime-local" required /></br>
<label for="ivrState">IVR Status"</label>
<select name="ivrState" id="ivrStatus" required>
<option disabled="disabled" selected="selected">Select</option>
<option value="fail">Failed</option>
<option value="pass">Passed</option>
</select>
</br>
</br>
<table>
<tr>
<td colspan="5">Customer Account Details:</td>
</tr>
<tr>
<td>Account Nr:</td>
<td><input type="text" name="accnt_1" placeholder="Account Info" id="accnt_1" required /></td>
<td> </td>
<td>Agreement nr:</td>
<td><input type="text" name="agree_1" placeholder="Agreement Info" id="agree_1" /></td>
</tr>
<tr>
<td>Account Nr:</td>
<td><input type="text" name="accnt_2" placeholder="Account Info" id="accnt_2" /></td>
<td> </td>
<td>Agreement nr:</td>
<td><input type="text" name="agree_1" placeholder="Agreement Info" id="agree_2" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>Agreement nr:</td>
<td><input type="text" name="agree_3" placeholder="Agreement Info" id="agree_3" /></td>
</tr>
</table>
</br>
Give a description: </br> <textarea rows="7" cols="100" minlength="50" id="descript" name="Description" required>Provide a description of min 50 characters.</textarea></br>
<input type="reset" value="Reset" onclick="reloadPage()" />
<input type="submit" value="Generate email" onclick="generateEmail()" />
</form>
</div>