0

How to remove the white space in Actual invoice amount the screen shot and code that are shown at the below cases.

<div class="form-group">
    <label class="col-sm-3 control-label">Actual Invoice Amount</label>
        <div class="col-sm-8">
             <input type="text" name="payment_act_invamt" id="act_invamt" class="form-control act_invamt"  placeholder="Actual Invoice Amount"   required>  
             </div>

enter image description here

reeversedev
  • 382
  • 1
  • 3
  • 18
Nishanth
  • 59
  • 3
  • 13

4 Answers4

2

Use the JavaScript trim() method. this method will remove white spaces from both side of string

function InvoiceAmount(){
    var input_value = document.getElementById("act_invamt").value;
    alert(input_value + "\n" + input_value.trim())
    
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group">
<label class="col-sm-3 control-label">Actual Invoice Amount</label>
<div class="col-sm-8">
<input type="text" name="payment_act_invamt" id="act_invamt" class="form-control act_invamt"  placeholder="Actual Invoice Amount"   required >

<button onclick="InvoiceAmount()">Click Here</button>
</div>

Here I have show difference of using trim method and without using trim method

Shakir Ahamed
  • 1,290
  • 3
  • 16
  • 39
  • 1
    Yes, this. And since your question is tagged with PHP, maybe [also do this server side](https://stackoverflow.com/questions/2109325/how-to-strip-all-spaces-out-of-a-string-in-php). – jonathanbell Dec 29 '17 at 06:06
0

var formvalue = $('input[name="somename"]').val();

formvalue = formvalue.trim();
    
$('input[name="somename"]').val(formvalue);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<form>
  <input type="text" name="somename" value="    9000">
  
</form>
TarangP
  • 2,711
  • 5
  • 20
  • 41
0

// Try this . i hope it's useful ..

var act_invamt = document.getElementById("act_invamt").value
var str = act_invamt.replace(/\s/g, '');

alert(str); die;
Nimesh Patel
  • 796
  • 1
  • 7
  • 23
0

you can use jQuery trim() which remove both left and right space, first show space with input value then when click remove space then remove space

 function removeSpace() {
    var inputvalue = $('input[name="payment_act_invamt"]').val();

    inputvalue = inputvalue.trim();

    $('input[name="payment_act_invamt"]').val(inputvalue);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
    <input type="text" name="payment_act_invamt" value="    9000">
    <input type="button" onclick="removeSpace()" value="Remove Space" />

</form>

so you can use this code which remove space from input filed

  var inputvalue = $('input[name="payment_act_invamt"]').val();

        inputvalue = inputvalue.trim();

        $('input[name="payment_act_invamt"]').val(inputvalue);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
    <input type="text" name="payment_act_invamt" value="    9000">

</form>
Shafiqul Islam
  • 5,570
  • 2
  • 34
  • 43