Print Page | Close Window

Help with JavaScript

Printed From: Web Wiz Forums
Category: Web Wiz Web App Support Forums
Forum Name: Web Wiz Forums
Forum Description: Support forum for Web Wiz Forums application.
URL: https://forums.webwiz.net/forum_posts.asp?TID=3829
Printed Date: 01 April 2026 at 11:08pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Help with JavaScript
Posted By: csosa
Subject: Help with JavaScript
Date Posted: 25 June 2003 at 12:33pm

I'm trying to modify a javascript in the forum but I need some help.

this is what I have

<script language="javaScript">

var test = "This is a Test";

var newString = test.replace(" ","");

</script>

I'm trying to delete the white spaces in the variable test but doing what I did it only deletes the first white space but the other ones don't go. so currently the newString variable comes with (Thisis a Test). How can I delete all the other blank spaces??

Thanks

Carlos




Replies:
Posted By: Commander
Date Posted: 28 June 2003 at 4:10pm
<SCRIPT LANGUAGE="JavaScript"> 
var test = "This is a Test";
var index = test.indexOf(" ");

while (index != -1) {
test = test.replace(" ", "");
index = test.indexOf(" ", index + 1);
}
alert(test);
</script>

 i took this aproach because replace() only seemed 2 replace only the first char..
a little late 4 a reply, but hope this helps



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net