I have a form called incident form. Its a form with over 90 fields and within this form I have several submit buttons. The first 2 are as follows:
<input type="submit" class="button" id="updateincidentButton" name="updateincidentButton" value="Update Incident">
<input type="submit" class="button" id="cancelincidentButton" name="cancelincidentButton" value="Cancel Incident">
They are my basic update the incident or if they don't want to, the user cancels the incident.
Within this form I wanted the user to be able to add a series of date ranges for work missed so I build within the form a "sub-form" which is just a div with some fields that add these date ranges for missed work. I build this section with an "Add Osha Days" button using jquery and ajax. This is submitted when the below button is clicked.
<input type="submit" name="saveoshadayssubmit" id="saveoshadayssubmit" value="Save OSHA Days" class="button rmargin3">
All this is working perfectly using submit button and a php processing file.
Now I am trying to use ajax to update the the add days records and refresh the part of the form that summarizes these days added records to no avail. Here is the jquery snippet I have written just to start testing this. It is not working as it just does the default form submit. In the code I am at this point just trying to capture the input in the div I have ided as "addoshadaysdiv". I am using an alert as I always to see if I am capturing the data I want. It does not seem to be working.
$(function(){
$("#saveoshadayssubmit").click(function(){
$("#incidentform").submit(function(event){
var formdata = $("#addoshadaysdiv *").serializeArray();
alert(formdata);
event.preventDefault();
})
})
As you can see I am trying to do this only on the "saveoshadayssubmit" button click. Any ideas on what I am doing wrong?
Here is the div code.
<div id="addoshadaysdiv">
<div class="paddingbottom3">
<label class="rmargin3 subtitle">OSHA Days</label>
<input type="hidden" name="oshadaysid" value="3">
</div>
<div class="paddingbottom3">
<input type="submit" name="saveoshadayssubmit" id="saveoshadayssubmit" value="Save OSHA Days" class="button rmargin3">
<input type="button" name="closeoshadayssubmit" value="Close OSHA Days" class="button">
</div>
<div>
<label for="oshastartdate" class="rmargin3">Start Date:</label>
<input type="text" id="oshastartdate" name="oshastartdate" value="01/03/2015" class="datepick eighth rmargin10">
<label for="oshaenddate" class="rmargin3">End Date:</label>
<input type="text" id="oshaenddate" name="oshaenddate" value="03/11/2015" class="datepick eighth rmargin10">
<label for="oshadaytypeid" class="rmargin3">OSHA Days Type:</label>
<select id="oshadaytypeid" name="oshadaytypeid">
<option value="3">Job Transfer</option>
<option value="2">Light Days</option>
<option value="1">Lost Days</option>
</select>
</div>
</div>