function q1_switch() { $('#q1rinput').hide(); if ($('#q1ryes:checked').length >= 1) $('#q1rinput').show(); } q1_switch(); $('.quest1').change(function() { q1_switch(); $('#q1rinput').val($(this).val()); });
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>test</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> </head> <?php $choices = array('oui', 'non', 'n/a'); if (!empty($_POST['mon_champ']) && is_array($_POST['mon_champ']) && !empty($_POST['mon_champ']['choice']) && in_array($_POST['mon_champ']['choice'], $choices) ) { echo 'Reponse: ', $_POST['mon_champ']['choice']; if ($_POST['mon_champ']['choice'] === 'oui') echo ' Texte: ', $_POST['mon_champ']['txt']; } ?> <form method="post" action=""> <fieldset> <legend>Question 1</legend> <label for="q1ryes">Oui</label> <label for="q1rno">Non</label> <label for="q1rna">N/A</label> " /> </fieldset> </form> <script type="text/javascript"> function q1_switch() { $('#q1rinput').hide(); if ($('#q1ryes:checked').length >= 1) $('#q1rinput').show(); } q1_switch(); $('.quest1').change(function() { q1_switch(); }); </script> </html>
lorsque je sélectionne oui je veux que le valeur 30 s'affiche dans le textbox.
value="30"
Plus je regarde votre code et moins je comprends le JS.
$choices = array('oui', 'non', 'n/a'); if (!empty($_POST['mon_champ']) && is_array($_POST['mon_champ']) && !empty($_POST['mon_champ']['choice']) && in_array($_POST['mon_champ']['choice'], $choices) ) { echo 'Reponse: ', $_POST['mon_champ']['choice']; if ($_POST['mon_champ']['choice'] === 'oui') echo ' Texte: ', $_POST['mon_champ']['txt']; else if ($_POST['mon_champ']['choice'] === 'non') echo ' Texte: ', $_POST['mon_champ']['txt']; else if ($_POST['mon_champ']['choice'] === 'n/a') echo ' Texte: ', $_POST['mon_champ']['txt']; }
function q1_switch() { $('#q1rinput').hide(); if ($('#q1ryes:checked').length >= 1) $('#q1rinput').show(); else if ($('#q1rno:checked').length >= 1) $('#q1rinput').show(); else if ($('#q1rna:checked').length >= 1) $('#q1rinput').show(); } q1_switch(); $('.quest1').change(function() { q1_switch(); $('#q1rinput').val($(this).val()); });