View Full Version : Finding and comparing a certain string of numbers within a value

01-21-2006, 11:09 PM
OK, I have multiple checkbox's and their values will consist of the following pattern type:


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.


01-22-2006, 12:02 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


<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){

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


01-22-2006, 12:24 AM
sweet, thanks