DaViDa
DaViDa

Reputation: 641

Escaping Variable white space

I got a html table and I'm retrieving the value of a cell with:

var orderid = document.getElementById("orderid"+row).innerText;

The value of the cell is an orderid for example 10234. However when I alert the variable it comes with whitespaces in the front of the string and in the back. This causes that a particular query can't compare database entries with the variable as those database entries haven't got the whitespaces. How do I trim this to just the 10234 without the white spaces around it?

Upvotes: 0

Views: 1414

Answers (2)

nice ass
nice ass

Reputation: 16719

If that's always a number, you can use parseInt(orderid). Otherwise, orderid.trim() (you need IE9+)

Upvotes: 1

Amit Sharma
Amit Sharma

Reputation: 1212

try using

stringToTrim.replace(/^\s+|\s+$/g,"")

Upvotes: 0

Related Questions