Question: I have this string

```
<img src="xxxxxx"/>     Title<br>Desc

```

How to replace double space into one space and also tag. please help. thanks.

I'm using following code (not working) :

```
preg_replace('<img src="(.*?)"\/>', "", $str, -1);

```

Thanks for help.

Answer: 
The problem is that onclick is being called everytime (even when its not going to submit by the browser).
You can fix by changing the onclick to onsubmit ([JSFiddle](http://jsfiddle.net/CvmP3/))

```
 <input class="button" id="submitbutton" type="submit" value="Submit" onsubmit="this.disabled=true;this.value='Sending Request';">

```
I would be tempted to bind to the `submit` event of the containing form, and use the concept from [\_.debounce](http://underscorejs.org/#debounce "underscore debounce") to limit the repetition of submissions:

jQuery:

```
// prevent the user from submitting the form twice within a second
var DELAY = 1000;
var lastSubmit = null;

$("#form").submit(function(e) {
  if (lastSubmit === null || Date.now() - lastSubmit > DELAY)
    return true;
  // two ways to prevent the default action
  e.preventDefault();
  return false;
});

```

Or staight JavaScript:

```
// prevent the user from submitting the form twice within a second
var DELAY = 1000;
var lastSubmit = null;

document.getElementById('form').addEventListener('submit', function(e) {
  if (lastSubmit === null || Date.now() - lastSubmit > DELAY)
    return true;
  // two ways to prevent the default action
  e.preventDefault();
  return false;
});

```

You can tune `DELAY` to meet your requirements, or handle the form submission failing to reset a disabled state.

If a requirement is to use attributes for the hooks, then:

```
echo "<form onsubmit=\"var stop = lastSubmit && Date.now() - lastSubmit <= 1000;stop && e.preventDefault();return !stop;\">";

```