Help - Space in script that splits string at comma

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hoggman

    #1

    Help - Space in script that splits string at comma

    Hi all

    take a look at http://www.beal-homes.com/test.asp

    I have used the script below to split a field down at commas and then
    created a new string

    This works but after the first item there is a space where the comma used to
    be, is there any way I can remove this?

    Thanks

    Matt Houldsworth



    <script language="javas cript">
    var devText="<%=(ho uses.Fields.Ite m("location").V alue)%>";

    function getDevelopments () {
    var input = devText.split(" ,");
    var input2 = new String();
    for (var i = 0; i<input.length ; i++) {
    input2 += "<a
    href='home_temp late.asp?id=<%= (houses.Fields. Item('id').Valu e)%>&titleofdev e
    lopment=" + input[i] + "'>" + input[i] + "</a>" +"<br>";
    } document.all("d ev").innerHTM L = input2;
    }
    </script>









  • Randy Webb

    #2
    Re: Help - Space in script that splits string at comma

    Hoggman wrote:
    [color=blue]
    > Hi all
    >
    > take a look at http://www.beal-homes.com/test.asp
    >
    > I have used the script below to split a field down at commas and then
    > created a new string
    >
    > This works but after the first item there is a space where the comma used to
    > be, is there any way I can remove this?
    >
    > Thanks
    >
    > Matt Houldsworth
    >
    >
    >
    > <script language="javas cript">
    > var devText="<%=(ho uses.Fields.Ite m("location").V alue)%>";[/color]

    The output of that server side code is this:
    var devText="Leaf Sail Farm, Church View, The Willows";

    That is where your spaces are coming from.

    To remove them, either remove them on the server or check the FAQ of
    this group for the Trim, LTrim and RTrim functions.
    [color=blue]
    > function getDevelopments () {
    > var input = devText.split(" ,");
    > var input2 = new String();
    > for (var i = 0; i<input.length ; i++) {
    > input2 += "<a
    > href='home_temp late.asp?id=<%= (houses.Fields. Item('id').Valu e)%>&titleofdev e
    > lopment=" + input[i] + "'>" + input[i] + "</a>" +"<br>";
    > } document.all("d ev").innerHTM L = input2;[/color]

    document.all is not a function.

    thats the error message Mozilla gives.

    While reading the FAQ, check on DynWrite

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    Working...