Je travail sur un projet et je but sur un problème.
J'ai un formulaire et j'ai des champs a cacher en fonction d'un selecteur.
Je ne sais pas comment faire, si quelqu'un sur le forum sais comment faire pourrait-il m'aider ?
c'est un bout de code.<form action="<?=htmlspecialchars($_SERVER['PHP_SELF'])?>" method="post">
<!-- bouton radio Civilite Nom et prenom -->
<div class="container">
<div class="row d-flex justify-content-center align-items-center">
<div class="col-5 col-lg-2 offset-lg-0 mb-3">
<select name="liens"
id="liens"
class="form-control">
<option value="">Liens *</option>
<?php foreach(ARRAY_LIENS as $value):?>
<option value="<?=$value?>" <?=$value==$liens ? 'selected' : ''?> ><?=$value?></option>
<?php endforeach?>
</select>
<?= htmlentities($error['liens'] ?? '', ENT_QUOTES, 'UTF-8')?>
</div>
<div class="col-5 col-lg-2 d-flex mb-3 texteFond">
<div class="form-check me-2">
<input class="form-check-input"
type="radio"
value="1"
name="civility"
id="civilityO"
<?= (!empty($civility) && $civility == "1") ? 'checked' : '' ?>>
<label class="form-check-label" for="civility0">Mme</label>
</div>
<div class="form-check me-2">
<input class="form-check-input"
type="radio"
value="2"
name="civility"
id="civility1"
<?= (!empty($civility) && $civility == "2") ? 'checked' : '' ?>>
<label class="form-check-label" for="civility1">Mlle</label>
</div>
<div class="form-check">
<input class="form-check-input"
type="radio"
value="3"
name="civility"
required
id="civility2"
<?= (!empty($civility) && $civility == "3") ? 'checked' : '' ?>>
<label class="form-check-label" for="civility2">Mr</label>
</div>
<div class="error"><br><?= htmlentities($error['civility'] ?? '', ENT_QUOTES, 'UTF-8')?></div>
</div>
<div class="col-10 col-lg-4">
<div class="form-floating mb-3">
<input type="text"
class="form-control"
minlenght ="2"
maxlength="25"
name="name"
id="name"
placeholder="Votre nom"
pattern="<?=REGEX_NO_NUMBER?>"
required
value="<?= htmlentities($_POST['name'] ?? '', ENT_QUOTES, 'UTF-8')?>">
<div class="error"><?= htmlentities($error['name'] ?? '', ENT_QUOTES, 'UTF-8')?></div>
<label for="name">Nom *</label>
</div>
</div>
<div class="col-10 col-lg-4 offset-lg-0">
<div class="form-floating mb-3">
<input type="text"
class="form-control"
minlenght ="2"
maxlength="25"
name="firstname"
id="firstname"
placeholder="Votre prénom"
pattern="<?=REGEX_NO_NUMBER?>"
required
value="<?= htmlentities($_POST['firstname'] ?? '', ENT_QUOTES, 'UTF-8')?>">
<div class="error"><?= htmlentities($error['firstname'] ?? '', ENT_QUOTES, 'UTF-8')?></div>
<label for="firstname">Prénom *</label>
</div>
</div>
</div>
</div>
<!-- Fin nom et prenom -->
Et voila la fonction js mais cela ne fonctionne pas au top.
Merci par avance de vos retours.const select = document.querySelector('select');
const birthday = document.querySelector('#birthday');
const mail = document.querySelector('#mail');
const mailConf = document.querySelector('#mailConf');
const telHome = document.querySelector('#telHome');
const telWork = document.querySelector('#telWork');
const salary = document.querySelector('#salary');
const commentaire = document.querySelector('#commentaire');
const falcultaty = [birthday,mail,mailConf,telHome,telWork,salary,commentaire];
select.onchange=(event)=>{
var selectedOption = event.target.value;
console.log(event.target.value);
if (selectedOption != "Mere" || selectedOption != "Pere"){
falcultaty.forEach(element=>{
element.classList.add("d-none");
})
} else {
falcultaty.forEach(element=>{
element.classList.remove("d-none");
})
}
}
@+ filou