title: Replace spaces javascript
body: <p>I have created a location to postcode form. The only trouble is the result of the postcode may contain 2 or more spaces. I would like to make sure that there isn't more than one space. In other words >1 space change to 1 space.</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;head&gt;
      &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          function showLocation(position) {
              var latitude = position.coords.latitude;
              var longitude = position.coords.longitude;
              $.getJSON('http://www.uk-postcodes.com/latlng/' + position.coords.latitude + ',' + position.coords.longitude + '.json?callback=?', null, gotpostcode);
          }
  
          function errorHandler(err) {
              if(err.code == 1) {
                  alert("Error: Access is denied!");
              } else if( err.code == 2) {
                  alert("Error: Position is unavailable!");
              }
          }
  
  
          function gotpostcode(result)
          {
              var postcode = result.postcode;
              $("#postcodegoeshere").val(postcode);
          }
  
          function getLocation(){
              if(navigator.geolocation){
                  // timeout at 60000 milliseconds (60 seconds)
                  var options = {timeout:60000};
                  navigator.geolocation.getCurrentPosition(showLocation, 
                                                           errorHandler,
                                                           options);
              } else {
                  alert("Sorry, browser does not support geolocation!");
              }
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;html&gt;
      &lt;body&gt;
          &lt;form&gt;
              &lt;input type="button" onclick="getLocation();"  
                                   value="Get Location"/&gt;
          &lt;/form&gt;
          &lt;div&gt;
              &lt;input id='postcodegoeshere' name='xxx' type='text' value='' /&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>