S
S
sargod2015-11-01 10:01:52
JavaScript
sargod, 2015-11-01 10:01:52

How to implement so that when you enter 2 digits in the input, the button changes color?

How to implement so that when you enter 2 digits in the input, the button changes color.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Michael, 2015-11-01
@Mikhail_RU

<form id="theForm" class="pure-form pure-form-stacked"> 
  <div>
    <label for="radius">Radius</label>
    <input type="text" name="radius" id="radius"/>
    <input type="submit" id="submit" value="Calculate" class="button-secondary pure-button"/>
  </div>
</form>

$('#radius').keypress(function() {
  var dInput = this.value;
  console.log(dInput.length);
  if (dInput.length >= 1) {
    if (!isNaN(dInput)) {
      $('input[type=submit]').addClass("button-error");
    }
  }
});

The whole example is here You
may need to do more checks on the input data.

A
Andrew, 2015-11-01
@R0dger

It is possible through bootstrap - getbootstrap.com/css/#forms-control-validation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question