Rendre une zone texte innaccéssible

Résolu/Fermé
bichbich - 16 mai 2013 à 20:43
 bichbich - 19 mai 2013 à 14:49
Bonsoir,j'ai un formulaire de recherche je veux quand l'utilisateur commence à saisir une zone,les autres seront désactivé,j'arrive pas à faire ça!s.v.p aidez moi


<form name="form2" method="post" action="recherchean.php">
<table width="455" border="0" bgcolor="#999933">

<tr>

<td width="182"><div align="center" class="style6">Annee :</div></td>
<td width="257"><input type='text' size="30" name="annee"maxlength="4" >
</td>
</tr>





<tr>
<td height="31" colspan="2">
<div align="right">
<input type="submit" name="bouton2" value="Chercher" align="right" />

</div></td>
</tr>
</table>


<div align="center"></div>
</form>

</div>



<form name="form2" method="post" action="rechercheetud.php">
<table width="455" border="0" bgcolor="#999933">

<tr>
<td width="178" align="center"><span class="style6">Nom & Prenom Etudiant :</span> </td>
<td width="261"><input type='text' size="30" name="nopetud" /></td>
</tr>
<tr>
<td height="31" colspan="2">

<div align="right">
<input type="submit" name="bouton3" value="Chercher" />

</div></td>
</tr>
</table>

</form>
</div>



<form name="form2" method="post" action="rechercheencadreur.php" >
<div align="center">
<table width="455" border="0" bgcolor="#999933">

<tr>
<td width="178"><div align="center" class="style6">Nom & Prenom Encadreur : </div></td>
<td width="259"><input type='text' size="30" name="noprencad" /></td>

<tr> </tr>
<tr>
<td height="31" colspan="2"><div align="right">
<input type="submit" name="bouton" value="Chercher" />
</div></td>
</tr>
</table>
</div>
<div align="center"></div>
</form>



<div align="center">



</div>
</form>
<div align="center"><form name="form2" method="post" action="recherchespt.php">
<table width="455" border="0" bgcolor="#999933">
<tr>
<td width="180"><span class="style6">La specialite:</span></td>
<td width="265"><select name="specialite" id="specialite">
<option selected="selected" value="0"></option>
<option value="informatique">informatique</option>
<option value="mathematique">mathématique</option>

</select></td>
</tr>
<tr>
<td height="31" colspan="2">
<div align="right">
<input name="a52" type="submit" value="chercher" />
</div></td></tr>
</table>

</form>

3 réponses

Profil bloqué
18 mai 2013 à 23:39
Bonsoir,
Après avoir corriger du mieux que pouvait le html, j'ai creer la fonction javascript pour faire ce que tu cherchait.

Voici donc le nouveau code:
<div class="form">
	<form name="form2" method="post" action="recherchean.php">
		<table width="455" border="0" bgcolor="#999933">
			<tr>
				<td width="182"><div align="center" class="style6">Annee :</div></td>
				<td width="257"><input type='text' class="disable" size="30" name="annee" maxlength="4" onfocus="disableOthers(this);" ></td>
			</tr>
			<tr>
				<td height="31" colspan="2">
					<div align="right">
						<input type="submit" name="bouton2" value="Chercher" align="right" />
					</div>
				</td>
			</tr>
		</table>
	</form>
</div>


<div class="form">
	<form name="form2" method="post" action="rechercheetud.php">
		<table width="455" border="0" bgcolor="#999933">
			<tr>
				<td width="178" align="center"><span class="style6">Nom & Prenom Etudiant :</span> </td>
				<td width="261"><input type='text' class="disable" size="30" name="nopetud" onfocus="disableOthers(this);" /></td>
			</tr>
			<tr>
				<td height="31" colspan="2">
					<div align="right">
						<input type="submit" name="bouton3" value="Chercher" />
					</div>
				</td>
			</tr>
		</table>
	</form>
</div>


<div class="form">
	<form name="form2" method="post" action="rechercheencadreur.php" >
		<table width="455" border="0" bgcolor="#999933">
			<tr>
				<td width="178"><div align="center" class="style6">Nom & Prenom Encadreur : </div></td>
				<td width="259"><input type='text' class="disable" size="30" name="noprencad" onfocus="disableOthers(this);" /></td>
			</tr>
			<tr>
				<td height="31" colspan="2">
					<div align="right">
						<input type="submit" name="bouton" value="Chercher" />
					</div>
				</td>
			</tr>
		</table>
	</form>
</div>

<div class="form">
	<form name="form2" method="post" action="recherchespt.php">
		<table width="455" border="0" bgcolor="#999933">
			<tr>
				<td width="180"><span class="style6">La specialite:</span></td>
				<td width="265">
					<select name="specialite" class="disable" id="specialite" onfocus="disableOthers(this);">
						<option selected="selected" value="0"></option>
						<option value="informatique">informatique</option>
						<option value="mathematique">mathématique</option>
					</select>
				</td>
			</tr>
			<tr>
				<td height="31" colspan="2">
					<div align="right">
						<input name="a52" type="submit" value="chercher" />
					</div>
				</td>
			</tr>
		</table>
	</form>
</div>
<script>
	function disableOthers(target) {
		x = document.getElementsByClassName('disable')
		for(i=0;i<x.length;i++) {
			x[i].setAttribute('disabled', 'disabled');
		}

		target.removeAttribute('disabled');
	}
</script>
0
merci bcp!
0
j'ai résolu le probléme via cet exemple;
<html>
<body>
<form>
<input type="text" id="firsttxt" value="" onkeyup="disableElement();"><br>
<input type="text" id="secondtxt" value="" onkeyup="disableElement();"><br>
<input type="text" id="thirdtxt" value="" onkeyup="disableElement();">
</form>

<script>

function disableElement()
{

b1 = (document.getElementById('firsttxt').value !== "");
b2 = (document.getElementById('secondtxt').value !== "");
b3 = (document.getElementById('thirdtxt').value !== "");

document.getElementById("firsttxt").disabled = b2 | b3;
document.getElementById("secondtxt").disabled = b1 | b3;
document.getElementById("thirdtxt").disabled = b1 | b2;
}

</script>
</body>
</html>
0