简体   繁体   中英

I want to break textbox value

I am using javascript to adding two textbox values and store that value in same textbox. For that process am using onmouseenter event. When i enter mouse in that textbox that textbox values increasing each time but i need to avoid it. Here i posted my code can you please solve it,

function removeFormField() {          
        var count_id = document.getElementById("balance").value;  
        document.getElementById('balance').value = parseInt(count_id)+10;   
}

HTML Code:

<div class="form-group">
     <label for="firstname" class="col-sm-4 control-label">Balance amount</label> 
        <div class="col-sm-6"> 
            <input type="text" class="form-control" id="balance" name="balance" placeholder="Balance amount" onmouseenter="removeFormField();"> 
        </div> 
</div> 

Use a flag to keep track of change

var allowChange = true;
function removeFormField() {          
    if(allowChange){
        var count_id = document.getElementById("balance").value;  
        document.getElementById('balance').value = parseInt(count_id)+10;
        allowChange = false;
    }   
}
<input type="text" class="form-control" id="balance" name="balance" placeholder="Balance amount" onkeypress="removeFormField()"> 

Only one change made on the input event. Changed to keypress and it is only called when you enter and input to field. and not when you click your mouse on to the field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM