diff --git a/docs/Lr4.pdf b/docs/Lr4.pdf new file mode 100644 index 0000000..8fd4202 Binary files /dev/null and b/docs/Lr4.pdf differ diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..b2bbed4 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,23 @@ + + + + + + Приветствие + + + + +

Введите имя и фамилию

+ + + + + + + + + +
+ + diff --git a/docs/index1.html b/docs/index1.html new file mode 100644 index 0000000..9b5fa90 --- /dev/null +++ b/docs/index1.html @@ -0,0 +1,30 @@ + + + + + + checkbox + + + + +
+

выберите товары

+ + + + + + + + + + + + +
+

Общая стоимость: 0 руб.

+ + + + diff --git a/docs/index2.html b/docs/index2.html new file mode 100644 index 0000000..65cfc74 --- /dev/null +++ b/docs/index2.html @@ -0,0 +1,49 @@ + + + + + + Оформление заказа + + + +

Оформление заказа

+ + + +

+ + +

+ + +

Товары:

+ + +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ + +

Итого: 0 руб.

+ + + + + + + diff --git a/docs/main.js b/docs/main.js new file mode 100644 index 0000000..d373b74 --- /dev/null +++ b/docs/main.js @@ -0,0 +1,17 @@ +document.addEventListener('DOMContentLoaded', () => { + const firstNameInput = document.getElementById('firstName'); + const lastNameInput = document.getElementById('lastName'); + const submitBtn = document.getElementById('submitBtn'); + const greetingDiv = document.getElementById('greeting'); + + submitBtn.addEventListener('click', () => { + const firstName = firstNameInput.value.trim(); + const lastName = lastNameInput.value.trim(); + + if (firstName && lastName) { + greetingDiv.textContent = `привет, ${firstName} ${lastName}!`; + } else { + greetingDiv.textContent = 'Пожалуйста, введите имя и фамилию.'; + } + }); +}); diff --git a/docs/main1.js b/docs/main1.js new file mode 100644 index 0000000..5385b84 --- /dev/null +++ b/docs/main1.js @@ -0,0 +1,15 @@ +document.getElementById('Btn').addEventListener('click', function() { + + const checkboxes = document.querySelectorAll('input[name="food"]:checked'); + + + let totalCost = 0; + + + checkboxes.forEach(function(checkbox) { + totalCost += parseInt(checkbox.value); + }); + + + document.getElementById('totalCost').textContent = totalCost; +}); diff --git a/docs/main2.js b/docs/main2.js new file mode 100644 index 0000000..fd0be7b --- /dev/null +++ b/docs/main2.js @@ -0,0 +1,85 @@ +// Функция для пересчета общей суммы +function updateTotalPrice() { + let total = 0; + + // Получаем все товары + const products = document.querySelectorAll('.product'); + + products.forEach(function(product) { + // Проверяем, выбран ли товар (чекбокс активен) + if (product.checked) { + // Получаем цену и количество товара + const price = parseFloat(product.getAttribute('data-price')); + const quantityField = document.getElementById(`quantity${product.id.slice(-1)}`); + let quantity = parseInt(quantityField.value); + + // Проверка на корректность ввода + if (isNaN(quantity) || quantity <= 0) { + quantity = 0; // Обнуляем некорректные значения + } + + // Если товар выбран, добавляем его стоимость к общей сумме + total += price * quantity; + } + }); + + // Обновляем итоговую сумму на странице + document.getElementById('totalPrice').textContent = total; +} + +// Функция для обработки выбора товара (чекбокса) +function handleCheckboxChange(event) { + const checkbox = event.target; + const quantityField = document.getElementById(`quantity${checkbox.id.slice(-1)}`); + + // Если чекбокс отмечен, устанавливаем количество 1, если снят - 0 + if (checkbox.checked) { + quantityField.value = 1; + } else { + quantityField.value = 0; + } + + // Пересчитываем итоговую сумму + updateTotalPrice(); +} + +// Функция для обработки изменения количества +function handleQuantityChange(event) { + const quantityField = event.target; + const value = parseInt(quantityField.value); + + // Если количество некорректное, обнуляем его + if (isNaN(value) || value < 0) { + quantityField.value = 0; + } + + // Если товар не выбран, обнуляем количество + const productCheckbox = document.getElementById(`item${quantityField.id.slice(-1)}`); + if (!productCheckbox.checked) { + quantityField.value = 0; + } + + // Пересчитываем итоговую сумму + updateTotalPrice(); +} + +// Функция для оформления заказа +function handleOrder() { + const lastName = document.getElementById('lastName').value.trim(); + const firstName = document.getElementById('firstName').value.trim(); + const totalPrice = document.getElementById('totalPrice').textContent; + + // Выводим модальное окно с информацией о заказе + alert(`Заказчик: ${lastName} ${firstName}\nИтого: ${totalPrice} руб.`); +} + +// Добавляем обработчики событий +document.querySelectorAll('.product').forEach(function(checkbox) { + checkbox.addEventListener('change', handleCheckboxChange); +}); + +document.querySelectorAll('.quantity').forEach(function(quantityField) { + quantityField.addEventListener('input', handleQuantityChange); +}); + +document.getElementById('orderBtn').addEventListener('click', handleOrder);