faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

65 of 71 people (92%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I use JavaScript to find 'spaces and replace them with 'underscores OnClick?

Apr 5th, 2008 20:26
ha mo, Tony Crosby, Kevin Smith, http://developer.netscape.com/viewsource/angus_strings.html


I would use .replace.
<script>
var MyString = "This is a test";
var pattern = / /g;
var MyNewString=MyString.replace(pattern,"_");
document.write(MyNewString);
</script>
 Tony
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com