+ Reply to Thread
Results 1 to 8 of 8

Thread: matching

  1. #1
    Barn Loyal todd2006 is an unknown quantity at this point todd2006's Avatar
    Join Date
    Mar 2008
    Posts
    889
    Rep Power
    4

    matching

    Hello,
    I have a textbox where a user enters a code and if the code he enters matches the database it should prompt a alert

    This is the code I have but its not working any idea

    Code:
    function calldiscounting()
    
    {
    
    
    
    var getdiscount=document.frm1.discount.value;
    
     
    
    var checkstring=/discounting/;
    
    var matchnow=getdiscount.search(checkstring);
    
     
    
    if(matchPos1 !=-1)
    
    {
    
                                    alert("discount good");
    
    }
    
    else
    
    {
    
                  
    
    }
    
     
    
     
    
     
    
    }
    
    If someone enters the code in lower case or upper case it doesnt work

    any help is highly appreciated

    thanks

    todd

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Where is matchPos1 set?

    If you use Firefox, the Error Console gives you more detailed JS error messages.

  3. #3
    Barn Loyal todd2006 is an unknown quantity at this point todd2006's Avatar
    Join Date
    Mar 2008
    Posts
    889
    Rep Power
    4

    richyrich

    I got the code from google. can u help me with it

    thanks

    todd

  4. #4
    Barn Loyal todd2006 is an unknown quantity at this point todd2006's Avatar
    Join Date
    Mar 2008
    Posts
    889
    Rep Power
    4

    I have the code like this now

    Code:
    function calldiscounting()
    
    {
    
    
    
    var getdiscount=document.frm1.discount.value;
    
     
    
    var checkstring=/discounting/;
    
    var matchnow=getdiscount.search(checkstring);
    
     var matchPos1=getdiscount.search(matchnow);
    
    if(matchPos1 !=-1)
    
    {
    
                                    alert("discount good");
    
    }
    
    else
    
    {
    
                  
    
    }
    
     
    
     
    
     
    
    }
    
    Last edited by micky; September 9th, 2010 at 05:05 AM. Reason: Added code tags, please do so in future

  5. #5
    Barn Loyal todd2006 is an unknown quantity at this point todd2006's Avatar
    Join Date
    Mar 2008
    Posts
    889
    Rep Power
    4

    richyrich,

    the above code works now but the problem is if someone enters the word in upper case it doesnt work

    i need to tweak the condition so it work for both upper case and lower case

    any idea how to do it



    todd

  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I would have thought this would work:-
    Code:
    function calldiscounting()
    
    {
    
    var getdiscount=document.frm1.discount.value;
    
    var checkstring=/discounting/;
    
    var matchPos1=getdiscount.search(checkstring.toLowerCase());
    
    if(matchPos1 !=-1)
    {
        alert("discount good");
    }
    else
    {
    }
    
    }
    
    The search method should return either a value or -1 if it doesn't find the string. I'm not sure of the relevance of the additional search method you call using matchnow.

  7. #7
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,382
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Or you can use a modifier on the RegEx to perform case insensitive matching:
    Code:
    var getdiscount=document.frm1.discount.value;
    var checkstring=/discounting/i;
    var matchPos1=getdiscount.search(checkstring);
    
    And @RR, I think you mean:
    Code:
    var matchPos1 = getdiscount.toLowerCase().search(checkstring);
    
    Last edited by Wolffy; September 8th, 2010 at 12:29 PM.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  8. #8
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by Wolffy View Post
    Or you can use a modifier on the RegEx to perform case insensitive matching:
    And @RR, I think you mean:
    Code:
    var matchPos1 = getdiscount.toLowerCase().search(checkstring);
    
    Yep. That is what I meant...

+ Reply to Thread

Similar Threads

  1. Matching on multiple field values
    By richyrich in forum SQL Development
    Replies: 32
    Last Post: May 12th, 2010, 09:34 PM
  2. 'If' must end with a matching 'End If'.
    By dibblejon in forum .NET Development
    Replies: 11
    Last Post: September 10th, 2009, 04:25 AM
  3. 'If' must end with a matching 'End If'.
    By dibblejon in forum ASP Development
    Replies: 2
    Last Post: September 9th, 2009, 11:27 AM
  4. Dynamically created ddl check if matching selections
    By peebman2000 in forum .NET Development
    Replies: 10
    Last Post: October 30th, 2008, 10:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO