Searching strings for matching text

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joeyej

    #1

    Searching strings for matching text

    Hi -

    Wondering if anyone knows how to code a function fieldcheck to prevent
    users from choosing the same date from dual drop list on my web form
    using this include file example;

    <option value="none">Sc roll through the list to choose a date
    <option value="May 11 2004, (Tuesday), 1pm">May 11 2004, (Tuesday),
    1pm
    <option value="May 11 2004, (Tuesday), 2:30pm">May 11 2004, (Tuesday),
    2:30pm

    I'd prefer to alert the user (return false) if this string ">May 11
    2004, is the same as this string ">May 11 2004, on the next line of
    the include file.

    I now have this code working nicely to prevent the same choice;

    FirstCh=documen t.laptop.FirstC h.value
    SecondCh=docume nt.laptop.Secon dCh.value

    if (FirstCh == "none" || SecondCh == "none" || FirstCh == SecondCh) {
    alert("Please choose two [different] dates/times for your laptop
    delivery.")
    document.laptop .FirstCh.focus( )
    return false
    }

    ....but I'd prefer to alert the user (return false) if this string
    ">May 11 2004, is the same as this string ">May 11 2004, on the next
    line of the include file.

    Your help is greatly appreciated.

    Thanks,

    Joe
  • Michael Winter

    #2
    Re: Searching strings for matching text

    On 15 Apr 2004 16:02:38 -0700, Joeyej <joseph.jasinsk i@quinnipiac.ed u>
    wrote:

    [snip]
    [color=blue]
    > ...but I'd prefer to alert the user (return false) if this string
    > ">May 11 2004, is the same as this string ">May 11 2004, on the next
    > line of the include file.[/color]

    /* This extracts the date section (all text before
    * the first comma) so it can be compared.
    */
    var fCD = FirstCh.substri ng( 0, First.indexOf( ',' ));
    var sCD = SecondCh.substr ing( 0, Second.indexOf( ',' ));

    if(( 'none' == FirstCh ) || ( 'none' == SecondCh ) || ( fCD == sCD ))
    {
    /*...*/
    }

    Hope that helps,
    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    Working...