lundi 26 septembre 2022

Javascript html form text&email&checkbox

This question is mainly about Javascript.

The contents you want to move include Fill in all the text, email, and checkboxes (one checkbox can be checked). The content is as follows: "Disabled" of "Submit" will be removed.

Here's the programming. There are two bugs that stand out in no way.

1, Once filled in or checked, it does not return to disabled even if it is deleted.

2、If you choose checkbox first, you can, disabled is not removed by filling in text, email,.

Please help us with fixes to the buggy parts and other movable Javascript solutions.

<form action="" method="POST">
<input type="text" id="txt" name="aaa" required onchange="manage(this)" />
<input type="email" id="ama" name="email" required onchange="manage(this)"/><br>

<label><input type="checkbox" name="sample[]" value="1" onchange="manage(this)">aaa1</label><br>
<label><input type="checkbox" name="sample[]" value="2" onchange="manage(this)">bbb2</label><br>
<label><input type="checkbox" name="sample[]" value="3" onchange="manage(this)">ccc3</label><br>
<label><input type="checkbox" name="sample[]" value="4" onchange="manage(this)">eee4</label><br>

<input type="submit" id="sager" value="O.K." disabled>
<input type="reset" value="Reset"></input>
</form>

<script>
function manage() {
  const txtJAB = document.getElementById('txt');
  const amaJAB = document.getElementById('ama');
  const submJAB = document.getElementById('sager');
  const chareJAB = document.querySelectorAll('input[name="sample[]"]:checked');

  if (txtJAB.value != '')
  if (amaJAB.value != '')
  if (chareJAB.length === '') {
    submJAB.disabled = true;
  }
  else {
    submJAB.disabled = false;
  }
}
</script>



Aucun commentaire:

Enregistrer un commentaire