Valeur par défaut pour une liste déroulante
chaima.abdouli
Messages postés
94
Date d'inscription
Statut
Membre
Dernière intervention
-
chaima.abdouli Messages postés 94 Date d'inscription Statut Membre Dernière intervention -
chaima.abdouli Messages postés 94 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
J'ai une liste déroulante pour chaque déclinaison soit couleur soit taille etc dans chaque fiche produit!
je veux qque pour chaque liste déroulante, un attribut s'affiche par défaut par exemple pour ma liste déroulante des couleurs je veux que l'affichage suivant se fait
<choisissez votre couleur>
Marron
Noir
Rouge
Voici le code gérant le choix!
Que dois-je faire?
J'ai une liste déroulante pour chaque déclinaison soit couleur soit taille etc dans chaque fiche produit!
je veux qque pour chaque liste déroulante, un attribut s'affiche par défaut par exemple pour ma liste déroulante des couleurs je veux que l'affichage suivant se fait
<choisissez votre couleur>
Marron
Noir
Rouge
Voici le code gérant le choix!
Que dois-je faire?
function choixStock(){ var balise=document.getElementById('etat-stock'); balise.innerHTML="Rupture/Sur Commande"; var couleur=document.getElementsByTagName('select')[1]; var taille=document.getElementsByTagName('select')[2]; var produit=document.getElementById('products_id'); var idsearch=produit.value+';'+taille.value+';'+couleur.value; //alert(idsearch); var key=document.getElementById(idsearch).value; if(key>0){ balise.innerHTML="Livre sous 2 a 5 jours ouvres"; }
A voir également:
- Valeur par défaut pour une liste déroulante
- Liste déroulante excel - Guide
- Liste déroulante en cascade - Guide
- Liste déroulante google sheet - Accueil - Guide bureautique
- Liste code ascii - Guide
- Supprimer liste déroulante excel - Forum Excel
2 réponses
Salut,
Tu peux simplement ajouter une option sans value au début de ta liste déroulante :
Bonne journée
Tu peux simplement ajouter une option sans value au début de ta liste déroulante :
<select> <option value="">Choisissez une couleur</option> <option value="marron">Marron</option> <option value="rouge">Rouge</option> <option value="noir">Noir</option> </select>
Bonne journée
Au pire, même s'il est plus propre de modifier la balise select lors qu'elle est générée par PHP, tu peux également modifier celle-ci en javascript au chargement de la page.
En ajoutant par exemple ce code javacript :
Par contre, ce code ne conserve pas un choix précédemment sélectionné (si une des options possède l'attribut selected à la génération). Il faudrait effectivement modifier ce code pour vérifier si un choix est déjà sélectionné, et si c'est le cas ne pas ajouter l'attribut selected sur le choix par défaut.
En ajoutant par exemple ce code javacript :
function initialiseSelect() { var selectCouleur = document.getElementsByTagName('select')[1]; var option = document.createElement('option'); option.text = 'Choisissez une couleur'; option.setAttribute('selected', 'selected'); selectCouleur.insertBefore(option, selectCouleur.firstChild); } window.addEventListener("load", initialiseSelect,false);
Par contre, ce code ne conserve pas un choix précédemment sélectionné (si une des options possède l'attribut selected à la génération). Il faudrait effectivement modifier ce code pour vérifier si un choix est déjà sélectionné, et si c'est le cas ne pas ajouter l'attribut selected sur le choix par défaut.
ça serait pas ce code que je dois modifier??
//SI ON TOUCHE AUX ATTRIBUTS if(isset($_POST['modifattrib'])){ $couleurexist; $tailleexist; $num=$_POST['num']; // COULEURS //on commence par les attrib deja existant au depart $sql="select options_values_id from products_attributes where options_id=1 and products_id=".$num.";"; $resultats=tep_db_query($sql); while($ligne=tep_db_fetch_array($resultats)){ $couleurexist[]=$ligne['options_values_id']; //si ces attrib sont decochés il faut les virer if(!isset($_POST['couleur'.$ligne['options_values_id']])){ $sql="delete from products_attributes where options_values_id=".$ligne['options_values_id']." AND " . "products_id=".$num.";"; tep_db_query($sql); } } //on recupere toutes les couleurs $sql="select products_options_values_id from products_options_values_to_products_options where products_options_id=1;"; $resultats=tep_db_query($sql); while($ligne= tep_db_fetch_array($resultats)){ //on verifie quel attrib sont cochés if(isset($_POST['couleur'.$ligne['products_options_values_id']])){ //si ce n'est pas un attrib deja existant if(!in_array($ligne['products_options_values_id'],$couleurexist)){ $sql="insert into products_attributes (products_id,options_id,options_values_id)" . "values ($num,1,".$ligne['products_options_values_id'].");"; tep_db_query($sql); } } }
Oui mais je vous ai montré un exemple y'a aucun formulaire avec un select dans tous les fichiers ils générent les options automatiquement comme celui la
<form name="wishlist_quantity" method="post" action="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_wishlist', 'NONSSL'); ?>"> <input type="hidden" name="products_id" value="<?php echo $product_info['products_id']; ?>"> <input type="hidden" name="products_model" value="<?php echo $product_info['products_model']; ?>"> <input type="hidden" name="products_name" value="<?php echo htmlspecialchars($product_info['products_name']); ?>"> <input type="hidden" name="products_price" value="<?php echo $product_info['products_price']; ?>"> <input type="hidden" name="final_price" value="<?php echo $product_info['final_price']; ?>"> <input type="hidden" name="products_tax" value="<?php echo $product_info['products_tax']; ?>"> <?php $wishlist_id_query = tep_db_query('select products_id as wPID from ' . TABLE_WISHLIST . ' where products_id= ' . $product_info['products_id'] . ' and customers_id = ' . (int)$customer_id . ' order by products_name'); $wishlist_Pid = tep_db_fetch_array($wishlist_id_query); if ( (!tep_not_null($wishlist_Pid[wPID])) && (tep_session_is_registered('customer_id')) ){ echo tep_template_image_submit('button_add_wishlist.gif', IMAGE_BUTTON_ADD_WISHLIST); } ?> </form>
<?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); ?><table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB;?>">
<?php
if ($product_check['total'] < 1) {
?>
<tr>
<td><?php new infoBox(array(array('text' => TEXT_PRODUCT_NOT_FOUND))); ?></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
<td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_template_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<?php
} else {
// BOF MaxiDVD: Modified For Ultimate Images Pack!
$product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description,"
. " p.products_model, p.products_quantity, p.products_image, p.products_image_med,"
. " p.products_image_lrg, pd.products_url, p.products_price, p.products_tax_class_id, "
. "p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, "
. TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" .
(int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" .
(int)$languages_id . "'");
// EOF MaxiDVD: Modified For Ultimate Images Pack!
$product_info = tep_db_fetch_array($product_info_query);
tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . (int)$languages_id . "'");
if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
$products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
} else {
$products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
}
if (tep_not_null($product_info['products_model'])) {
$products_name = $product_info['products_name'] . '<br><span class="smallText">[' . $product_info['products_model'] . ']</span>';
} else {
$products_name = $product_info['products_name'];
}
?>
<?php
// BOF: WebMakers.com Added: Show Featured Products
if (SHOW_HEADING_TITLE_ORIGINAL=='yes') {
$header_text = ' ';
?>
<tr>
<td>
<!-- FICHE PRODUIT -->
<table class="ficheproduit">
<tr>
<td class="big-image-produit">
<img id="first-image" src="<?php echo DIR_WS_IMAGES .$product_info['products_image'] ?>">
</td>
<td class="side-bar-product" rowspan="2">
<h3><?php echo $products_name; ?></h3>
<h4 class="prix-produit"><?php echo $products_price; ?></h4>
<div class="description-produit">
<p>
<?php
if($product_info['products_description']!=''){
echo stripslashes($product_info['products_description']);
}
else{
echo "<br /><br />PAS DE DESCRIPTION DISPONIBLE";
}
?>
</p>
</div>
<br />
<!-- ATTRIBUTS PRODUITS -->
<?php
echo "<input type='hidden' id='products_id' value='".(int)$HTTP_GET_VARS['products_id']."'>";
$declinaisons_query= tep_db_query("select * from declinaison_stock_produit where products_id=".(int)$HTTP_GET_VARS['products_id'].";");
$declinaison_array=array();
while($declinaison= tep_db_fetch_array($declinaisons_query)){
$name=$declinaison['products_id'].';'.$declinaison['taille_attributs'].';'.$declinaison['couleur_attributs'];
echo "<input type='hidden' id='".$name."' value='".$declinaison['stock']."'>";
$declinaison_array[]=array('id_prod' => $declinaison['products_id'],'id_taille' => $declinaison['taille_attributs'],
'id_couleur' => $declinaison['couleur_attributs'],'upc' => $declinaison['upc'],'stock' => $declinaison['stock']);
}
$products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
$products_attributes = tep_db_fetch_array($products_attributes_query);
if ($products_attributes['total'] > 0) {
$products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_id asc");
while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
$products_options_array = array();
$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "' order by pov.products_options_values_id ASC");
while ($products_options = tep_db_fetch_array($products_options_query)) {
$products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);
if ($products_options['options_values_price'] != '0') {
$products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
}
}
if (isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
$selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
} else {
$selected_attribute = false;
}
// AFFICHAGE
echo "<p class='detail-produit'>";
echo "<u>".$products_options_name['products_options_name'] . '</u> :';
echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute,'onChange="choixStock(this)"');
echo "</p>";
}
}
?>
<input type="hidden" name="quantity" value="1" maxlength="3" size="3">
<?php
echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_template_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART,'align="right"'); ?>
</form>
<form name="wishlist_quantity" method="post" action="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_wishlist', 'NONSSL'); ?>">
<input type="hidden" name="products_id" value="<?php echo $product_info['products_id']; ?>">
<input type="hidden" name="products_model" value="<?php echo $product_info['products_model']; ?>">
<input type="hidden" name="products_name" value="<?php echo htmlspecialchars($product_info['products_name']); ?>">
<input type="hidden" name="products_price" value="<?php echo $product_info['products_price']; ?>">
<input type="hidden" name="final_price" value="<?php echo $product_info['final_price']; ?>">
<input type="hidden" name="products_tax" value="<?php echo $product_info['products_tax']; ?>">
<?php
$wishlist_id_query = tep_db_query('select products_id as wPID from ' . TABLE_WISHLIST . ' where products_id= ' . $product_info['products_id'] . ' and customers_id = ' . (int)$customer_id . ' order by products_name');
$wishlist_Pid = tep_db_fetch_array($wishlist_id_query);
if ( (!tep_not_null($wishlist_Pid[wPID])) && (tep_session_is_registered('customer_id')) ){
echo tep_template_image_submit('button_add_wishlist.gif', IMAGE_BUTTON_ADD_WISHLIST,'align="left"');
}
?>
<p id="etat-stock" onload="choixStock()">Selectionnez une taille</p>
</form>
</td>
</tr>
<tr>
<td>
<center>
<table class="galerie-photo-produit">
<tr>
<?php
// AFFICHAGE GALERIE IMAGES
$products_images_query=tep_db_query("select products_image_sm_1,products_image_sm_2,products_image_sm_3,
products_image_sm_4,products_image_sm_5,products_image_sm_6 from " . TABLE_PRODUCTS . " where "
. "products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "'");
$products_image=tep_db_fetch_array($products_images_query);
for($i=1;$i<=6;$i++){
$image="products_image_sm_".$i;
if($products_image[$image]!=''){
echo"<td><img src='". DIR_WS_IMAGES .$products_image[$image] ."' onclick='changeImage(this)'></td>";
}
}
?>
</tr>
</table>
</center>
</td>
</tr>
</table>
</td>
</tr>
<?php
} else{
$header_text = $products_name .'</td><td background="' . DIR_WS_TEMPLATES . TEMPLATE_NAME . '/images/infobox/background.gif" align="right" class="productlisting-headingPrice">' . tep_draw_separator('pixel_trans.gif', '100%', '4') . $products_price;
}
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(false, false, $header_text);
}
// EOF: Lango Added for template MOD
//Commented for x-sell
// if ((USE_CACHE == 'true') && empty($SID)) {
// echo tep_cache_also_purchased(3600);
// } else {
// include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
// }
// }
//Added for x sell
if ( (USE_CACHE == 'true') && !SID) {
echo tep_cache_also_purchased(3600);
include(DIR_WS_MODULES . FILENAME_XSELL_PRODUCTS);
}
else {
include(DIR_WS_MODULES . FILENAME_XSELL_PRODUCTS_BUYNOW);
echo tep_draw_separator('pixel_trans.gif', '100%', '10');
include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
}
}
?>
</td>
</tr>
</table>
</code>
Sinon