tags:

views:

156

answers:

2
var html = "<div>"+title+"<br/>";
document.write(title.replace(/ /g,"-"));
html+= '<p><a href="go.aspx?title=' + title + '">Details<\/a></p></div>';

hi all,i want to replace title space with dash

+2  A: 

Try title.replace(/\s/g , "-") instead. (/\s/ is the regex escape for whitespace).

Also, do:

title = title.replace(/\s/g , "-");
var html = "<div>" + title + "</div>";
// ...
ehdv
+2  A: 

Calling title.replace will not change title, but return a string where the values have been replaced. You need to use the returned value:

var html = "<div>"+title+"<br/>";
var newTitle = document.write(title.replace(/ /g,"-"));
html+= '<p><a href="go.aspx?title=' + newTitle + '">Details<\/a></p></div>';

The regular expression is fine, but will only replace spaces and not all whitespace.

Oded
i got undefined in google maps..
ruru