Javascript – End Date not before Start Date

0

Hello, I have a form for users to submit with a start and an end date, however, I’m trying to introduce a validity function so that the end users can not set an end date that’s prior to a start date.

I asked in chat support for SG and it was suggested that I could achieve this with javascript.

Being as I don’t write javascript I quickly found an article on stackoverflow that seemed to have a solution (Source: http://stackoverflow.com/questions/833997/validate-that-end-date-is-greater-than-start-date-with-jquery)

 

See attached image, it won’t let me paste code, it comes out odd.

with the note:

Reference jquery.validate.js and jquery-1.2.6.js. Add a startDate class to your start date textbox. Add an endDate class to your end date textbox.

So I proceeded to add a Javascript Action that looks like this, yet it does not work:

document.write(“\<script src=’//jqueryjs.googlecode.com/files/jquery-1.2.6.js’ type=’text/javascript’>\<\/script>”);

document.write(“\<script src=’//ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.js’ type=’text/javascript’>\<\/script>”);

$(document).ready(function() {
$.validator.addMethod(“endDate”, function(value, element) {
var startDate = $(‘.startDate’).val();
return Date.parse(startDate) <= Date.parse(value) || value == “”;
}, “* End date must be after start date”);
$(‘#formId’).validate();
});

Any thoughts/suggestions? 

Thank you!

 

WFMZ Online asked
    0

    Hello!

    I can’t speak to the jQuery.validate plugin directly, but have a few suggestions for your script.

    1. Instead of using document.write to load your dependencies, put these <script> tags directly in the Custom <head> section of your survey theme.
    2. SurveyGizmo already loads the jQuery library in all surveys, so you don’t have to worry about loading that specifically.

    Aside from those stylistic suggestions, I would suggest checking in the console for any error messages. Very often this will contain the answer to your problem :)

    I hope this helps!

    Nathan - Survey Astronaut answered
      ×

      Login

      Question stats

      • Active
      • Views1507 times
      • Answers1 answer
      • Followers0 followers