Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string length

Status
Not open for further replies.

deejayAr

Technical User
Joined
Mar 20, 2008
Messages
126
Location
US
I have following function
function sortlistC(id) {
var lb = document.getElementById(id);
arrTexts = new Array();

for(i=1; i < lb.length; i++) {
arrTexts = lb.options.text+':'+lb.options.value;
}
arrTexts.sort();
for(i=1; i < lb.length; i++) {
el = arrTexts.split(':');
lb.options.text = el[0];
lb.options.value = el[1];}
all I need to get the lb.length -1 so I can get 1 less then the entire length of string
please help me to know how to do this in javascript
thank you very much

 
Hi

I think you need this :
JavaScript:
[b]function[/b] [COLOR=darkgoldenrod]sortlistC[/color][teal]([/teal]id[teal])[/teal]
[teal]{[/teal]
  [b]var[/b] lb [teal]=[/teal] document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal]id[teal]);[/teal]
  arrTexts [teal]=[/teal] [b]new[/b] [COLOR=darkgoldenrod]Array[/color][teal]();[/teal]

  [b]for[/b] [teal]([/teal]i[teal]=[/teal][purple]1[/purple][teal];[/teal] i [teal]<[/teal] lb[teal].[/teal]length[teal];[/teal] i[teal]++)[/teal] [teal]{[/teal]
    arrTexts[teal][[/teal]i[highlight][teal]-[/teal][purple]1[/purple][/highlight][teal]][/teal] [teal]=[/teal] lb[teal].[/teal]options[teal][[/teal]i[teal]].[/teal]text[teal]+[/teal][green][i]':'[/i][/green][teal]+[/teal]lb[teal].[/teal]options[teal][[/teal]i[teal]].[/teal]value[teal];[/teal]
  [teal]}[/teal]
  arrTexts[teal].[/teal][COLOR=darkgoldenrod]sort[/color][teal]();[/teal]
  [b]for[/b] [teal]([/teal]i[teal]=[/teal][purple]1[/purple][teal];[/teal] i [teal]<[/teal] lb[teal].[/teal]length[teal];[/teal] i[teal]++)[/teal] [teal]{[/teal]
    el [teal]=[/teal] arrTexts[teal][[/teal]i[highlight][teal]-[/teal][purple]1[/purple][/highlight][teal]].[/teal][COLOR=darkgoldenrod]split[/color][teal]([/teal][green][i]':'[/i][/green][teal]);[/teal]
    lb[teal].[/teal]options[teal][[/teal]i[teal]].[/teal]text [teal]=[/teal] el[teal][[/teal][purple]0[/purple][teal]];[/teal]
    lb[teal].[/teal]options[teal][[/teal]i[teal]].[/teal]value [teal]=[/teal] el[teal][[/teal][purple]1[/purple][teal]];[/teal]
  [teal]}[/teal]
[teal]}[/teal]

Feherke.
 
Thank you very much
it is good help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top