Here's my 3 minute attempt:



  _____  

From: Nathan R. Jessop [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 19, 2004 1:57 PM
To: CF-Talk
Subject: RE: **UPDATE** Arrange sequential selections into ranges how to???

Maybe I've made it more difficult than it has to be.

Ignore the <select> stuff.

Let's say I have a variable being passed to my action page that contains the
following (this can vary):

var1 = "1,2,3,4,5,6,10,11,12,13,14,20,25,30,31,32,33,50"

How can I arrange the above variable into a range. Meaning...how can I take
any input from the variable and basically create a new varaible with the
following:

var2 = "1-14,20,25,30-33,50"

Notice that if the numbers run consequtively they are "grouped" starting
with first then last separated by a hyphen.

Is this possible? I know what I want to do but its how to implement it.

>> I need to pass it like  1-16,23-25,30,33,40-42,46-48 to the server.

On Wed, 19 May 2004 17:41:35 +0200, Pascal Peters wrote:

>Rename your select "filelistselect",
>create a hidden field named "filelist"
>and call this JS function in the onsubmit of the form:
>
>function makeList(thisform){
> var opts = thisform.filelistselect.options,
>     val="",
>     i=0;
> for(;i<opts.length;i++){
> if(opts[i].selected){
> if(i==0 || !opts[i-1].selected){
> val += ((val.length>0)?",":"") +
>opts[i].value;
> }
> else if(i==opts.length-1 ||
>!opts[i+1].selected){
> val += "-" + opts[i].value;
> }
> }
> }
> thisform.filelist.value = val;
> thisform.filelistselect.disabled = true;
>}
>
><form ... > >
>Pascal
>
>
>>
>>
>> I need to pass it like  1-16,23-25,30,33,40-42,46-48 to the server.
>>
>> >> <select name="filelist" size="15" multiple class="dirlinks">
>> >>
>> >> <cfloop INDEX="i" FROM="1" TO="#ArrayLen(arPages)#">
>> >>
>> >> <cfset sVal = Trim(ListFirst(arPages[i], ">"))>
>> >>
>> >> <cfset sDisp = Trim(ListLast(arPages[i], ">"))>
>> >>
>> >> <cfset sValNoComma = NumberFormat(sVal, "9999999999")>
>> >>
>> >> <cfset sVal = NumberFormat(sVal)>
>> >>
>> >> <option value="#sValNoComma#">Seq:
>> >> #sValNoComma#&nbsp;&nbsp;Folio: #sDisp##spacer1#</option>
>> >>
>> >> </cfloop>
>> >>
>> >> </select>
>
>
>

  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to