Page 1 sur 1

bouton radio

Posté : 09 avr. 2011, 16:48
par luci
salut j'ai un problème avec les boutons radios
j'ai un formulaire où il y a plusieurs boutons radios et je veux exiger une condition:il faut cocher une valeur parmis le proposé(0,2,4,7)avant de passer aux radio suivant de telle façon que si un bouton n'est pas coché une alerte devra s'afficher voila un extrait de code:
<html>.........
<tr><td>intellegent</td>
<td><input type="radio" name="intellegent" value="0"> 0</td>
<td> <input type="radio" name="intellegent" value="2"> 2 </td>
<td><input type="radio" name="intellegent" value="4"> 4 </td>
<td><input type="radio" name="intellegent" value="7"> 7 </td></tr>
......
<tr><td>gourment</td>
<td><input type="radio" name="gourment" value="0"> 0</td>
<td> <input type="radio" name="gourment" value="2"> 2 </td>
<td><input type="radio" name="gourment" value="4"> 4 </td>
<td><input type="radio" name="gourment" value="7"> 7 </td></tr>

Re: bouton radio

Posté : 09 avr. 2011, 17:01
par moogli
salut,

il te faut le faire en javascript ;)


@+

Re: bouton radio

Posté : 09 avr. 2011, 17:37
par - HXSS -
<?PHP
$intellegent = isset($_POST['intellegent']) ? $_POST['intellegent'] : "";
$gourment = isset($_POST['gourment']) ? $_POST['gourment'] : "";

if (isset($_POST['ok'])) {

if ($intellegent == '') { $result = 'champ 1 vide';}
elseif ($gourment == '') { $result = 'champ 2 vide';}

}
?>
<html>
<head>
<title>essai</title>
</head>
<body>

<form action="essai.php" method="post">
<table>
<tr>
<td>intellegent</td>
<td><input type="radio" name="intellegent" value="0" <?PHP if($intellegent == "0") { echo 'checked="checked"'; }?>> 0</td>
<td> <input type="radio" name="intellegent" value="2" <?PHP if($intellegent == "2") { echo 'checked="checked"'; }?>> 2 </td>
<td><input type="radio" name="intellegent" value="4" <?PHP if($intellegent == "4") { echo 'checked="checked"'; }?>> 4 </td>
<td><input type="radio" name="intellegent" value="7" <?PHP if($intellegent == "7") { echo 'checked="checked"'; }?>> 7 </td></tr>

<tr><td>gourment</td>
<td><input type="radio" name="gourment" value="0" <?PHP if($gourment == "0") { echo 'checked="checked"'; }?>> 0</td>
<td> <input type="radio" name="gourment" value="2" <?PHP if($gourment == "2") { echo 'checked="checked"'; }?>> 2 </td>
<td><input type="radio" name="gourment" value="4" <?PHP if($gourment == "4") { echo 'checked="checked"'; }?>> 4 </td>
<td><input type="radio" name="gourment" value="7" <?PHP if($gourment == "7") { echo 'checked="checked"'; }?>> 7 </td></tr>
<tr><td><input type="submit" value="valider" name="ok"></td></tr>
</table>
</form>

<?PHP if (isset($result)) { echo $result; } ?>
</body>
</html>
c'est sûrement pas parfait mais l'idée est là :?