S
S
Stacy None2019-01-17 08:53:20
Node.js
Stacy None, 2019-01-17 08:53:20

How to check multiple input fields for text?

There are lines like this:

function check() {
  if ($('#zagol').val() != '')
    $('#zag').removeAttr('disabled');
  else
    $('#zag').attr('disabled','disable');
}

The script checks the zagol field for text and activates the button if text is entered.
It is necessary to redo the script so that it checks several fields. For example, there is also a #users field and a separate button for this field.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
Z
zooks, 2016-05-31
@zooks

You need to update the plugin to gulp-refresh .

S
Somewhere Intech, 2019-01-17
@Stacy11

In your case, it's better to refuse selection by id in favor of class .
If the button, then you can do this.<input type="submit">

<form>
     <input type="text" class="checkme" value="zagol">
     <!-- Другие элементы формы -->
     <input type="submit">
</form>
<form>
     <input type="text" class="checkme" value="users">
     <!-- Другие элементы формы -->
     <input type="submit">
</form>

Can you do it like this
function check(){
  if ($(this).val() !== '') $(this).parent().find('input[type="submit"]').removeAttr("disabled");
  else $(this).parent().find('input[type="submit"]').attr('disabled', true);
}
$(".checkme").change(check);

If the markup goes in pairs
<input type="text" class="checkme">
<button>#Загол</button>
<!-- Другие элементы -->
<input type="text" class="checkme">
<button>#Юзеры</button>

then you can change the check function like this
function check(){
  if ($(this).val() !== '') $(this).next('button').removeAttr("disabled");
  else $(this).next('button').attr('disabled', true);
}
$(".checkme").change(check);

A
Alexey G, 2019-01-17
@lem89

Look to the side
$('form').find('input').each(.....);

A
Andrey Okhotnikov, 2019-01-17
@tsepen

Like this https://codepen.io/tsepen/pen/vvwXXp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question