/    Sign up×
Community /Pin to ProfileBookmark

Validate dynamic date pairs

I am using ColdFusion to create a dynamic form based on the results of a database query. The form lists assets that are available to book on a project. Users then book as many of the assets as they want by selecting a start and end date for each asset from a popup calendar (each asset can have different start/end dates).

Upon clicking the Submit button I need to validate each pair of dates for the following:

  • 1.

    Ensure that both a start and end date were entered for each asset (it’s OK if both start/end are blank, just not one or the other)

  • 2.

    Ensure that the end date of the pair is not earlier than the start date.

  • I don’t have hard-coded field names because I don’t know the size of the query. Therefore each start date field is named [FONT=courier new]#q_listing.identifier_id#_start[/FONT] and each end date field is named [FONT=courier new]#q_listing.identifier_id#_end[/FONT] (where #q_listing.identifier_id# is the ID of the asset). On my processing page I parse apart the field name to determine the ID and whether or not it’s a start or end field.

    I’m just not sure how to get the dynamic field names into JS validation so that it compares the correct pair values.

    Any ideas? Thanks a bunch in advance!!

    to post a comment
    JavaScript

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @CharlesNov 30.2004 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

    "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <meta name="Content-Script-Type" content="text/javascript">

    <meta name="Content-Style-Type" content="text/css">

    <title>Example</title>

    <script type="text/javascript">

    <!--

    function check (f) {

    var set, i = 0;

    while (set = f.getElementsByTagName ('FIELDSET')[i++]) {

    var start = set.getElementsByTagName ('INPUT')[0];

    var end = set.getElementsByTagName ('INPUT')[1];

    if (/S/.test (start.value) ^ /S/.test (end.value)) {alert (1); return false};

    if (/S/.test (start.value) && (new Date (start.value) > new Date (end.value))) {alert (2); return false}

    }

    }

    // -->

    </script>

    <style type="text/css">

    <!--

    form {width:15em}

    fieldset {padding:1ex}

    label {display:block; text-align:right}

    button {display:block; margin:auto}

    -->

    </style>

    </head>

    <body>

    <form action="some-script.pl" onsubmit="return check (this)">

    <fieldset>

    <legend>Set one</legend>

    <label>Start Date <input type="text"></label>

    <label>End Date <input type="text"></label>

    </fieldset>

    <fieldset>

    <legend>Set two</legend>

    <label>Start Date <input type="text"></label>

    <label>End Date <input type="text"></label>

    </fieldset>

    <div><button type="submit">Submit</button></div>

    </form>

    </body>

    </html>[/font]
    ×

    Success!

    Help @xsw1971 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...