Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding and comparing a certain string of numbers within a value

    OK, I have multiple checkbox's and their values will consist of the following pattern type:

    SR1234567-SD1234567-1

    The numbers folloing SR will be differnt on each checkbox, as well as the single digit on the end. The numbers following SD however will be the same on certain checkboxes.

    So i'll have all the checkboxes in a colum, then when I click on one the script will look for the characters following the SD or between the "SD and "-". Then when I click the next checkbox it will check to see if the SDxxx number is the same value as the first one I clicked, if yes then alert "are the same" if not then alert "not the same", or something like that. This would continue every time you check a checkbox, it would loop though and make sure all of the checked checkboxes have the same numbers after SD.

    One other thing is the numbers after "SD" won't be a specific number of characters long, so it might be easiest to pull any numbers between "SD" and "-" as i mentioned above. I just dont know how do to that.

    Thanks!

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,518
    Thanks
    3
    Thanked 506 Times in 493 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    var Last;
    function CkSD(obj){
     var val=obj.value.substring(obj.value.indexOf('SD'),obj.value.lastIndexOf('-'));
     if (Last==val){
      alert('Same');
     }
     Last=val;
    }
    //-->
    </script></head>
    
    <body>
    <input value="SR1234567-SD1234567-1" onclick="CkSD(this);" ><br>
    <input value="SR1234567-SD123567-1" onclick="CkSD(this);" ><br>
    <input value="SR1234567-SD1234567-1" onclick="CkSD(this);" ><br>
    </body>
    
    </html>

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sweet, thanks


  •  

    Posting Permissions

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