Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing leading white space

Status
Not open for further replies.

meenu24

Programmer
May 5, 2006
37
US
Hi,

I am using the following code to replace the blank spaces.
This is value selectedText receives.
selectedText =     somevalue;
I want "somevalue"
With the following code I still receive the same old value.
var space = /^\s+/;
selectedText = selectedText.replace(space,"");

I am using IEBrowser.
What am I missing

Thanks



 
This works in IE:
Code:
<script>

String.prototype.htmlUnencode = function(){
  var div = document.createElement("div");
  div.innerHTML = this;
  return div.innerText;
}

String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,''); }

var test = "&nbsp;&nbsp;&nbsp;&nbsp;somevalue";
alert(test.htmlUnencode().trim());

</script>

Adam
 
Thanks Adam

Code:
   selectedText[i] = selectedText[i].replace(/^\s+|\s+$/g,'');
theSelTo.options[theSelTo.options.length]=new Option(selectedText[i],selectedValues[i],true,true);

I used above code, still I get the same value with blank spaces in the option field.

Where am I going wrong.

Thanks
Meena
 
Are you getting spaces or are you getting a bunch of &nbsp; entities like you posted? Have you tried the code I posted that converts the HTML encoded text (such as &nbsp;) into regular text?

Adam
 
Thanks Adam, I forgot to use the encoder now it works like magic!

thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top