Searching strings for matching text

Discussion in 'Javascript' started by Joeyej, Apr 16, 2004.

  1. Joeyej

    Joeyej Guest

    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">Scroll 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=document.laptop.FirstCh.value
    SecondCh=document.laptop.SecondCh.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
     
    Joeyej, Apr 16, 2004
    #1
    1. Advertising

  2. On 15 Apr 2004 16:02:38 -0700, Joeyej <>
    wrote:

    [snip]

    > ...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.


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

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

    Hope that helps,
    Mike

    --
    Michael Winter
    d (replace ".invalid" with ".uk" to reply)
     
    Michael Winter, Apr 17, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris
    Replies:
    5
    Views:
    8,125
    Christopher R. Barry
    Oct 11, 2003
  2. anonym
    Replies:
    1
    Views:
    1,073
    Knute Johnson
    Jan 15, 2009
  3. Karin Lagesen

    matching strings in a large set of strings

    Karin Lagesen, Apr 29, 2010, in forum: Python
    Replies:
    13
    Views:
    471
    Bryan
    May 3, 2010
  4. Helmut Jarausch
    Replies:
    3
    Views:
    345
    Dave Angel
    Apr 30, 2010
  5. Filippo
    Replies:
    1
    Views:
    122
    Filippo
    Apr 8, 2007
Loading...

Share This Page