0
Hello,
have a input called expense, and the entered value may not be greater than 1,000.00, if it’s greater than 1,000.00 appears a modal onscreen.
Could you help me in how to make this javascript, please?
0
Hello,
have a input called expense, and the entered value may not be greater than 1,000.00, if it’s greater than 1,000.00 appears a modal onscreen.
Could you help me in how to make this javascript, please?
3
You can use the addEventListener()
, from there you can take the value and make the check:
INPUT_OBJECT.addEventListener('input', function (evento) {
alert(this.value);
});
Any doubt I’m available!
Source: Pure Javascript Listen to input
1
There is a simple and easy solution to your problem using only Html5.
<!DOCTYPE html>
<html>
<body>
<form>
<input type="number" required="true" name="price" min="0" max="1000.00" step=".01">
</form>
</body>
</html>
Explanation of tags
If you want your input to have negative values, simply remove the attribute min.
I hope I helped and welcome to stackoverflow!
1
in that
if($('#gasto').val() >= 1000.00){
leave the value as numericIf the input is comma, you have to replace the comma by period to be able to compare
$(function() {
$(".btn-gasto").click(function() {
if($('#gasto').val() >= 1000.00){
//alert('Para o seu consumo iremos tratar o seu orçamento e projeto de forma exclusiva. ');
$("#myModal").modal('show');
event.preventDefault();
} else{
alert('menor que 1000.');
}
});
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<form name="calculadora" method='post' action='https://www.sunkit.com.br/resultado/'>
<input type="tel" id="gasto" name="gasto" placeholder="R$ 0.00" required>
<button type="submit" name="submit" class="btn-gasto">Calcular</button>
</form>
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Consumo acima de R$1000.00 </h4>
</div>
<div class="modal-body">
<p>Para o seu consumo iremos tratar o seu orçamento e projeto de forma exclusiva.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
The method
preventDefault
, that as the name already gives idea, prevents the default behavior of the object, ie cancels the behavior that elements usually have on the page, then, in this case, prevents the click of the button submit the form
Browser other questions tagged javascript html css
You are not signed in. Login or sign up in order to post.
You know the attribute
max
? And what do you know about javascript? Have you tried something? What was the difficulty?– Woss
yes, I don’t want to do with max. I had made a script, but I deleted it because it was giving too much error
– Richard
the idea would be for the person to type 1000.00 in the field and click the calculate button, and it appear the message, only an Alert after I turn here
– Richard
Could you describe how you asked the question? Give us a basis of what you know, what your difficulty was, what mistakes they made, etc. As it stands, you seem to be asking us to do it for you. Why don’t you want to use
max
?– Woss
Ola carlos, the script is this https://jsfiddle.net/4npemgvq/
– Richard
Editing the reversed question because the "new" question is completely different from the original, invalidating all current answers.
– Woss
You must use Event.preventDefault() to prevent Ubmit, and use the form’s Ubmit instead of the https://jsfiddle.net/7kr1g4md/1 button click/
– edson alves