Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Help - Space in script that splits string at comma

Reply
Thread Tools

Help - Space in script that splits string at comma

 
 
Hoggman
Guest
Posts: n/a
 
      08-17-2004
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[i] + "'>" + input[i] + "</a>" +"<br>";
} document.all("dev").innerHTML = input2;
}
</script>









 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      08-17-2004
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[i] + "'>" + input[i] + "</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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Re: SAX parser splits URL ... mayeul.marguet Java 0 06-27-2012 09:32 AM
Re: SAX parser splits URL ... Robert Klemme Java 1 06-27-2012 06:21 AM
a simple command that splits up a string into numbers and letters shawn bright Ruby 6 02-05-2009 07:02 AM
How to toggle between window splits? =?Utf-8?B?a2Q=?= ASP .Net 0 05-02-2005 11:34 AM



Advertisments