Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Выпадающий список в HTML. Отображение данных в зависимости от значения из списка (https://javascript.ru/forum/dom-window/69749-vypadayushhijj-spisok-v-html-otobrazhenie-dannykh-v-zavisimosti-ot-znacheniya-iz-spiska.html)

рони 16.07.2017 20:53

maxx787,
для кого всё выше писалось, непонятно ... :(

maxx787 16.07.2017 20:59

Посмотрите пожалуйста, где я мог допустить ошибку?
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Пример</title>
 </head>
 <body> 
  <script type="text/javascript">
fruit.onchange = function(argument) {
  if (limon.selected) {
    vec.innerHTML = "50";
    cena.innerHTML = "40";
  };
  if (orange.selected) {
    vec.innerHTML = "30";
    cena.innerHTML = "20";
  };
}
  </script>
  
<select id="fruit">
  <option value="1" id="orange">апельсин</option>
  <option value="2" id="limon">лимон</option>
</select>
<br/>
<table border="1" class="m">
  <tr>
    <td width="50px">Вес</td>
    <td width="50px"> Цена</td>
  </tr>
  <tr>
    <td id="vec" height="20px"></td>
    <td id="cena"></td>
  </tr>
</table>  
 </body>

рони 16.07.2017 21:07

maxx787,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  </style>

  <script>
 window.addEventListener("DOMContentLoaded", function() {
    var select = document.querySelector(".fruit"),
        img = document.querySelector(".show"),
    weight = document.querySelector(".weight"), 
    price = document.querySelector(".price");
    select.addEventListener("change", function() {
        var obj = {
            orange: {
                weight: 60,
                price: 80,
                src: "http://umeha.3dn.ru/img-o/orangel-150612.jpg"
            },
            limon: {
                weight: 20,
                price: 40,
                src: "http://sad-ogorod-svoimi-rukami.ru/wp-content/uploads/2012/09/images43.jpg"
            }
        }[select.value];
        if (obj) {
            weight.innerHTML = obj.weight;
            price.innerHTML = obj.price;
            img.src = obj.src
        }
    })
});
  </script>
</head>

<body>
<select class="fruit">
  <option value="orange" >апельсин</option>
  <option value="limon" >лимон</option>
</select>
<br/>
<table border="1" class="m">
  <tr>
    <td width="50px">Вес</td>
    <td width="50px"> Цена</td>
  </tr>
  <tr>
    <td class="weight" height="20px">60</td>
    <td class="price">80</td>
  </tr>
</table>
<img src="http://umeha.3dn.ru/img-o/orangel-150612.jpg" alt="" class="show">
</body>
</html>

maxx787 16.07.2017 21:10

Огромнейшее спасибо!!:)


Часовой пояс GMT +3, время: 22:44.