Javascript bouton radio

Résolu/Fermé
kyride - 17 mars 2010 à 10:03
swoog42 Messages postés 1059 Date d'inscription mercredi 30 septembre 2009 Statut Membre Dernière intervention 16 décembre 2018 - 17 mars 2010 à 10:34
Bonjour,

je dois selon la page cocher une case differente
Par exemple "page libraire" je coche la case librairies donc voici mon code



				<form method = "post" action = "adherent.php" >
					<div style="top:25px;">
						<input type = "image" src = "Images/map-fr.png" alt = "submit button" tabindex = "90" id = "image_form" />
						<ul id = "list_metier">
							<li>
								<input type = "radio" name = "metier" value = "lib" id = "lib"  tabindex = "10" />
			 					<label for = "lib">Librairie - Papeterie</label>
							</li>
							<li>
			 	  				<input type = "radio" name = "metier" id = "entreprise" value = "entreprise" tabindex = "20" />
			 		  			<label for = "entreprise">Entreprise</label>
							</li>
							<li>
								<input type = "radio" name = "metier" id = "education" value = "education" tabindex = "30" />
					  			<label for = "education">Education</label>
							</li>
							<li>
   								<input type = "radio" name = "metier" id = "enfance" value = "enfance" tabindex = "40" />
 	 							<label for = "enfance">Petite Enfance</label>
							</li>
							<li>
								<label for = "select_dep">Dep</label>
		 						<select  name = "select_dep" id = "select_dep" tabindex = "50">
								<?php
									$i = 1;
			   						while ($i <= 95)
			     	  					{	
				  	  					if ($i == 1)
				       	    			 			echo "<option value = \"".$i."\" selected = \"selected\">"."0".$i."</option>";
										else
										{
											if (strlen($i) == 1)
								  				echo "<option value = \"".$i."\">"."0".$i."</option>";
											else
												echo "<option value = \"".$i."\">".$i."</option>";
										}
					    	  			 $i++;
			     						}
								?>
		   						</select>
							</li>
						</ul>
						<div id = "button_form">
				      			<a href = "adherent.php" onclick = "change_url(this, 'dom');" onmouseup = "change_img_on_click('Images/b-dom-on.png', 'dom_button');"  onmousedown = "change_img_on_click('Images/b-dom-off.png', 'dom_button');"><img src = "Images/b-dom-on.png" alt = "boutton_dom" id = "dom_button"/></a><a href = "adherent.php" onclick = "change_url(this, 'tom');" onmouseup = "change_img_on_click('Images/b-tom-on.png', 'tom_button');"  onmousedown = "change_img_on_click('Images/b-tom-off.png', 'tom_button');"><img src = "Images/b-tom-on.png" alt = "boutton_tom" id = "tom_button" /></a><a href = "adherent.php" onclick = "change_url(this, 'oth');" onmouseup = "change_img_on_click('Images/b-pays-on.png', 'other_count_button');" onmousedown = "change_img_on_click('Images/b-pays-off.png', 'other_count_button');"><img src = "Images/b-pays-on.png" alt = "autre pays" id = "other_count_button"/></a>
						</div>
					</div>
		 		</form>
			</div> <!-- distrib -->
		</div> <!-- top header -->
	</div> <!-- header_site -->
	<!--le test pour cocher les cases-->
	<?php
	switch ($_SERVER["PHP_SELF"]) <!-- donc la je recuperer par exemple /libraire.php-->
		{
		case "/librairie.php";
				?><script>alert('<?=$_SERVER["PHP_SELF"]?>');document.form[0].list_metier.metier.checked=true;</script><?php
				break;
		}
	?>



Donc via le switch je voudrai cocher une case differentes selon l'url mais rien ne fonctionne 

Auriez vous une astuce? ( je suis censé respecter les normes w3c au passage)

Cdt





A voir également:

4 réponses

swoog42 Messages postés 1059 Date d'inscription mercredi 30 septembre 2009 Statut Membre Dernière intervention 16 décembre 2018 244
17 mars 2010 à 10:16
remplace les "name" par "id" et dans ton code, change
document.recherche.metier[0].checked=true;


par
document.getElementById("metier").checked=true;" 


Pour voir ce que ca donne.
1
super ca marche mais c'est pas

document.getElementById("metier").checked=true;

Mais

document.getElementById("lib").checked=true;
--> metier c'est le "name" =)

Merci swoog =)

u're my bill gates
1
Quand je met dans mon test "document.recherche.metier[0].checked=true;" ca fonctionne mais le W3C ne supporte pas l'attribut name sur le form donc euhh =8 mais quand je test avec un form[0] ca passe pas
0
swoog42 Messages postés 1059 Date d'inscription mercredi 30 septembre 2009 Statut Membre Dernière intervention 16 décembre 2018 244
17 mars 2010 à 10:34
Pas de problème ^^
0