jquery find input before button
I have a single form on the page and I have some jQuery to make sure that
the inputs have been completed before the submit.
But now I need to have multiple similar forms repeated on the page and I
need to change the jQuery to only check the two inputs in the form that
the button was clicked and not check any other form on the page.
<div class="offerDate">
<form class="form-inline hidden-phone"
action="http://www.treacyswestcounty.com/bookings/" method="get">
<fieldset>
<input type="text" name="from_date" placeholder="dd/mm/yy"
id="from_date" class="input-small hasDatepicker">
<input type="text" name="to_date" placeholder="dd/mm/yy"
id="to_date" class="input-small hasDatepicker">
<button id="submitDates" class="btn btn-main"
type="submit">CHECK NOW</button>
</fieldset>
</form>
</div>
<div class="offerDate">
<form class="form-inline hidden-phone"
action="http://www.treacyswestcounty.com/bookings/" method="get">
<fieldset>
<input type="text" name="from_date" placeholder="dd/mm/yy"
id="from_date" class="input-small hasDatepicker">
<input type="text" name="to_date" placeholder="dd/mm/yy"
id="to_date" class="input-small hasDatepicker">
<button id="submitDates" class="btn btn-main"
type="submit">CHECK NOW</button>
</fieldset>
</form>
</div>
The jQuery that I have used previously to check on form using ID
// validate signup form on keyup and submit
jQuery('#submitDates').click(function () {
var found = false;
jQuery("#to_date, #from_date").each(function(i,name){
// Check if field is empty or not
if (!found && jQuery(name).val()=='') {
alert ('Please choose your arrival and departure dates!')
found = true;
} ;
});
return !found;
});
No comments:
Post a Comment