![]() |
| |||||||
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
| |||
| 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 |
| ||||
| Try this: Code: strvar = strvar.substring(1, strvar.length-1);
__________________ jmurrayhead Did I help you out? Make me popular by clicking the icon!If you found a post helpful, please click the button in the lower right-hand corner of the post.Powered by ASP.Net |
| |||
| 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);
}
|
| ||||
| 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: Strife: As long as we have each other, we'll never run out of problems. Questions to Ponder: Should vegetarians eat animal crackers? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright © 2008 sbenj69 |
| |||
| 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 |
| ||||
| 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);
}
|
| |||
| 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 |
| ||||
| 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 | |
|
|
| Sponsored Links |
| ASP.NET Resource Index a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer. Free Web Directory Including Chats and Forums Resources, Offer automatic, instant and free directory submissions. | URLZ Web Directory URLZ Web Directory Free Web Directory - Add Your Link The Little Web Directory | Free Web Directory Pegasus free web directory is a free directory organised by categories. Web Directory & SEO Services dirroot web directory |