Help - Space in script that splits string at comma

Discussion in 'Javascript' started by Hoggman, Aug 17, 2004.

  1. Hoggman

    Hoggman Guest

    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="javascript">
    var devText="<%=(houses.Fields.Item("location").Value)%>";

    function getDevelopments() {
    var input = devText.split(",");
    var input2 = new String();
    for (var i = 0; i<input.length; i++) {
    input2 += "<a
    href='home_template.asp?id=<%=(houses.Fields.Item('id').Value)%>&titleofdeve
    lopment=" + input + "'>" + input + "</a>" +"<br>";
    } document.all("dev").innerHTML = input2;
    }
    </script>
     
    Hoggman, Aug 17, 2004
    #1
    1. Advertising

  2. Hoggman

    Randy Webb Guest

    Hoggman wrote:

    > 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="javascript">
    > var devText="<%=(houses.Fields.Item("location").Value)%>";


    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.

    > function getDevelopments() {
    > var input = devText.split(",");
    > var input2 = new String();
    > for (var i = 0; i<input.length; i++) {
    > input2 += "<a
    > href='home_template.asp?id=<%=(houses.Fields.Item('id').Value)%>&titleofdeve
    > lopment=" + input + "'>" + input + "</a>" +"<br>";
    > } document.all("dev").innerHTML = input2;


    document.all is not a function.

    thats the error message Mozilla gives.

    While reading the FAQ, check on DynWrite

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq
     
    Randy Webb, Aug 17, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?a2Q=?=

    How to toggle between window splits?

    =?Utf-8?B?a2Q=?=, May 2, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    466
    =?Utf-8?B?a2Q=?=
    May 2, 2005
  2. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,956
    Bryan Bullard
    Jul 11, 2003
  3. shawn bright
    Replies:
    6
    Views:
    107
    shawn bright
    Feb 5, 2009
  4. Robert Klemme

    Re: SAX parser splits URL ...

    Robert Klemme, Jun 27, 2012, in forum: Java
    Replies:
    1
    Views:
    288
    Robert Klemme
    Jun 27, 2012
  5. mayeul.marguet

    Re: SAX parser splits URL ...

    mayeul.marguet, Jun 27, 2012, in forum: Java
    Replies:
    0
    Views:
    245
    mayeul.marguet
    Jun 27, 2012
Loading...

Share This Page