![]() |
| |||||||
| Sponsored Links |
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| Hi, I have this variable strvar alert(strvar); the strvar variable holds values like this FDS, SDFR, strvar=FDS, SDFR, I want to remove the last comma after SDFR Can someone tell me the javascript function for it todd |
| Sponsored Links |
|
#2
| ||||
| ||||
| Try this: Code: strvar = strvar.substring(1, strvar.length-1);
__________________ jmurrayhead If you agree with me... click the icon! If my post solved your problem, click the button in the lower right-hand corner of the post.If you like it here...throw us a few bones to help support us. Join our Folding team: DeveloperBarn Folding |
|
#3
| |||
| |||
| hi, i want to show the cities selected by user seperated by comma but i want the last comma to be removed i tried ur code but it still displays the comma Code:
function calldro()
{
len = document.frm1.cityopt.length
i = 0
strvar = ""
for (i = 0; i < len; i++)
{
if (document.frm1.cityopt[i].selected)
{
strvar = strvar + document.frm1.cityopt[i].value + ", "
}
}
alert(strvar);
strvar = strvar.substring(1, strvar.length-1);
}
|
|
#5
| |||
| |||
| i did jmurrayhead it didnt work out |
|
#6
| ||||
| ||||
| from what i can see, when you're building that var .. you're adding a comma and a space between each word ... try this Code: } strvar = strvar.substring(1, strvar.length-2); alert(strvar); }
__________________ Quote of the Month: Quality: The race for quality has no finish line- so technically, it's more like a death march. Questions to Ponder: What do you do when you see an endangered animal eating an endangered plant? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright © 2008 sbenj69 |
|
#7
| |||
| |||
| Jmuurayhead, The code is cutting a character on the left side of the string and still keeping the comma at the end i want it to cut the comma on the right side todd |
|
#8
| ||||
| ||||
| Your code should look like this: Code: function calldro()
{
len = document.frm1.cityopt.length
i = 0
strvar = ""
for (i = 0; i < len; i++)
{
if (document.frm1.cityopt[i].selected)
{
strvar = strvar + document.frm1.cityopt[i].value + ", "
}
}
strvar = strvar.substring(1, strvar.length-2);
alert(strvar);
}
|
|
#9
| |||
| |||
| Ok, Now here is the problem this is my string strvar=FDS, SDFR, when i use the code you guys gave me this is the output strvar=DS, SDFR It removed the "F" also the first character in string todd |
|
#10
| ||||
| ||||
| You're right...do this: Code: function calldro()
{
len = document.frm1.cityopt.length
i = 0
strvar = ""
for (i = 0; i < len; i++)
{
if (document.frm1.cityopt[i].selected)
{
strvar = strvar + document.frm1.cityopt[i].value + ", "
}
}
strvar = strvar.substring(0, strvar.length-2);
alert(strvar);
}
|
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|