Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <head>
- <title>TODO supply a title</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
- <style>
- input[type=button]{
- width: 120px;
- height: 30px;
- background-color: darkblue;
- border-style: none;
- border-radius: 6px;
- font-size: 30px;
- }
- body{background-color: lightblue;
- }
- #cont{
- margin-left: 290px;
- }
- img{
- width: 150px;
- height: 150px;
- margin: 10px;
- }
- #typy{
- margin-top: -5px;
- position: absolute;
- background-color: black;
- margin-left: 27%;
- }
- .pamieci{
- float: left;
- border: solid 2px;
- margin: 10px;
- margin-top: 30px;
- background-color: black;
- color: white;
- }
- .inp{
- margin-left: 45px;
- }
- .inpp{
- margin-left: 70px;
- }
- #cena{
- float: left;
- height: 50px;
- width: 80px;
- background-color: lightgreen;
- margin-left: -297px;
- border-radius: 5px;
- position: absolute;
- }
- input[type=submit]{
- background-color: red;
- border-radius:6px;
- border-style: none;
- text-align: center;
- }
- .txtarea{
- float:left;
- position: fixed;
- margin-top: 30px;
- }
- </style>
- </head>
- <body>
- <div id="typy">
- <input type="button" value="DDR1" onclick="pamieci(this.value);">
- <input type="button" value="DDR2" onclick="pamieci(this.value);">
- <input type="button" value="DDR3" onclick="pamieci(this.value);">
- <input type="button" value="DDR4" onclick="pamieci(this.value);">
- <input type="button" value="Koszyk" onclick='wyswietlKoszyk();'>
- </div>
- <div id="cont">
- </div>
- <div id="pods">
- </div>
- <script>
- pamiecRAM = {
- 'RAM001': {'id':'1', 'typ': 'DDR1', 'pojemnosc': "500MB", 'taktowanie': "2400", "netto": "200,99zł", 'producent': 'GoodRam', 'obraz': 'ddr1.jpg'},
- 'RAM002': {'id':'2', 'typ': 'DDR1', 'pojemnosc': "1GB", 'taktowanie': "2400", "netto": "100zł", 'producent': 'GoodRam', 'obraz': 'ddr1.jpg'},
- 'RAM003': {'id':'3', 'typ': 'DDR4', 'pojemnosc': "6GB", 'taktowanie': "2400", "netto": "300,50zł", 'producent': 'GoodRam', 'obraz': 'ddr4.jpg'},
- 'RAM004': {'id':'4', 'typ': 'DDR2', 'pojemnosc': "1GB", 'taktowanie': "2400", "netto": "180,49zł", 'producent': 'GoodRam', 'obraz': 'ddr2.jpg'},
- 'RAM005': {'id':'5', 'typ': 'DDR4', 'pojemnosc': "8GB", 'taktowanie': "2400", "netto": "400zł", 'producent': 'GoodRam', 'obraz': 'ddr4.jpg'},
- 'RAM006': {'id':'6', 'typ': 'DDR1', 'pojemnosc': "1GB", 'taktowanie': "2400", "netto": "130,89zł", 'producent': 'GoodRam', 'obraz': 'ddr1.jpg'},
- 'RAM007': {'id':'7', 'typ': 'DDR2', 'pojemnosc': "2GB", 'taktowanie': "2400", "netto": "190,19zł", 'producent': 'GoodRam', 'obraz': 'ddr2.jpg'},
- 'RAM008': {'id':'8', 'typ': 'DDR3', 'pojemnosc': "4GB", 'taktowanie': "2400", "netto": "250,99zł", 'producent': 'GoodRam', 'obraz': 'ddr3.jpg'},
- 'RAM009': {'id':'9', 'typ': 'DDR1', 'pojemnosc': "500MB", 'taktowanie': "2400", "netto": "70zł", 'producent': 'GoodRam', 'obraz': 'ddr1.jpg'},
- 'RAM010': {'id':'10', 'typ': 'DDR4', 'pojemnosc': "8GB", 'taktowanie': "3000", "netto": "370zł", 'producent': 'GoodRam', 'obraz': 'ddr4.jpg'},
- 'RAM011': {'id':'11', 'typ': 'DDR2', 'pojemnosc': "1GB", 'taktowanie': "2400", "netto": "180,49zł", 'producent': 'GoodRam', 'obraz': 'ddr2.jpg'},
- 'RAM012': {'id':'12', 'typ': 'DDR2', 'pojemnosc': "1GB", 'taktowanie': "2400", "netto": "140,49zł", 'producent': 'GoodRam', 'obraz': 'ddr2.jpg'},
- 'RAM013': {'id':'13', 'typ': 'DDR3', 'pojemnosc': "4GB", 'taktowanie': "2400", "netto": "210,99zł", 'producent': 'GoodRam', 'obraz': 'ddr3.jpg'},
- 'RAM014': {'id':'14', 'typ': 'DDR3', 'pojemnosc': "2GB", 'taktowanie': "2400", "netto": "190zł", 'producent': 'GoodRam', 'obraz': 'ddr3.jpg'},
- 'RAM015': {'id':'15', 'typ': 'DDR3', 'pojemnosc': "4GB", 'taktowanie': "2400", "netto": "250zł", 'producent': 'GoodRam', 'obraz': 'ddr3.jpg'},
- 'RAM016': {'id':'16', 'typ': 'DDR4', 'pojemnosc': "8GB", 'taktowanie': "2400", "netto": "320,49zł", 'producent': 'GoodRam', 'obraz': 'ddr4.jpg'}
- };
- function pamieci(typ){
- var html = "";
- var zmien = 0;
- for(i in pamiecRAM){
- if(pamiecRAM[i]['typ']===typ){
- html+= "<div class='pamieci'>";
- html+= "<img src="+pamiecRAM[i]['obraz']+">";
- html+= "<ul style='list-style-type:square'>\n\
- <li>"+pamiecRAM[i]['typ']+"</li>";
- html+= "<li>"+pamiecRAM[i]['pojemnosc']+"</li>";
- html+= "<li>"+pamiecRAM[i]['taktowanie']+"MHz</li>";
- html+= "<li>"+pamiecRAM[i]['producent']+"</li>";
- html+= "<li>"+pamiecRAM[i]['netto']+"</li></ul>";
- html+= "<input id=" +i+ " class='inp' type='submit' value='Do koszyka' onclick='DoKoszyka(this.id)'>";
- html+= "</div>";
- zmien++;
- }
- }
- document.getElementById("cont").innerHTML = html;
- }
- class koszyk{
- constructor(index, ilosc,p){
- this.p=p;
- this.index = index;
- this.ilosc = ilosc;
- }
- }
- var produkt = new Array();
- function DoKoszyka(index){
- var exists=false;
- for(let i=0; i<produkt.length; i++){
- if(produkt[i].index===index){
- produkt[i].ilosc++;
- exists=true;
- break;
- }
- }
- if(exists === false){
- produkt.push(new koszyk(index, 1));
- }
- }
- function wyswietlKoszyk(){
- var html = "";
- var pods ="";
- var zmien=0;
- suma = 0;
- for(var i=0; i<produkt.length; i++){
- html+= "<div class='pamieci'>";
- html+= "<img src="+pamiecRAM[produkt[i].index]['obraz']+">";
- html+= "<ul style='list-style-type:square'>\n\
- <li>"+pamiecRAM[produkt[i].index]['typ']+"</li>";
- html+= "<li>"+pamiecRAM[produkt[i].index]['pojemnosc']+"</li>";
- html+= "<li>"+pamiecRAM[produkt[i].index]['taktowanie']+"MHz</li>";
- html+= "<li>"+pamiecRAM[produkt[i].index]['netto']+"</li>";
- html+= "<li>"+pamiecRAM[produkt[i].index]['producent']+"</li></ul>";
- html+= "<br>Ilość: <input type='number' min=1 value="+produkt[i].ilosc+" \n\
- onchange='zmienIlosc("+i+",this)'><br>";
- html+= "<input type='hidden' class='typ' value='"+ pamiecRAM[produkt[i].index].typ +"'>";
- html+= "<input type='hidden' class='pojemnosc' value='"+ pamiecRAM[produkt[i].index].pojemnosc +"'>";
- html+= "<input type='hidden' class='taktowanie' value='"+ pamiecRAM[produkt[i].index].taktowanie +"'>";
- html+= "<input type='hidden' class='netto' value='"+ pamiecRAM[produkt[i].index].netto +"'>";
- html+= "<input type='hidden' class='producent' value='"+ pamiecRAM[produkt[i].index].producent +"'>";
- html+= "<class='przycisk'><input id=" +i+ " class='inpp' type='submit' value='Usun' onclick='usun(this)'>";
- html+= "</div>";
- zmien++;
- suma+= parseFloat(produkt[i].ilosc*pamiecRAM[produkt[i].index].netto);
- html+="<div id='cena'> Cena: " +suma;
- html+="</div>";
- document.getElementById('cont').innerHTML=html;
- }
- pods+= "<br><br><br><table style='position:fixed; float:left; margin-top:-150px'> <tr><td> Uzupełnij dane:<br> <br> Imię: </td><td><br> <br><input id='imie' type='text' placeholder='np. Jan'></td></tr>";
- pods+= "<br><tr><td>Nazwisko: </td><td><input id='nazwisko' type='text' placeholder='np. Kowalski'></td></tr>";
- pods+= "<br><tr><td>Adres: </td><td><input id='adres' type='text' placeholder='np. Szczawa 100'></td></tr>";
- pods+= "<br><tr><td>Kod pocztowy: </td><td><input id='kod' type='text' placeholder='np. 34-607'></td></tr>";
- pods+= "<br><tr><td>Numer kontaktowy: </td><td><input id='tel' type='text' placeholder='np.555 555 555'></td></tr> ";
- pods+="<br><tr><td><input id='pods' style='font-size: 10px; position:fixed; float:left;' type='button' value='Podsumuj' onclick='podsumuj()'> </td></tr><br><br>";
- pods+= "<tr><td><textarea class='txtarea' name='info'>"+text+"</textarea></td></tr><br><br>";
- pods+= "<br><br><tr><td><input id='kup' style='font-size: 10px; position:fixed; float:left;margin-top:90px;' type='button' value='Zamów produkty!' onclick='mail()'> </td></tr><br><br></table>";
- document.getElementById('pods').innerHTML=pods;
- }
- text="";
- function podsumuj(){
- text+="Imie: "+document.getElementById("imie").value+"\n";
- text+="Nazwisko: "+document.getElementById("nazwisko").value+"\n";
- text+="Adres: "+document.getElementById("adres").value+"\n";
- text+="Kod pocztowy: "+document.getElementById("kod").value+"\n";
- text+="Telefon: "+document.getElementById("tel").value;
- wyswietlKoszyk();
- }
- function mail(){
- }
- function usun(i){
- produkt.splice(i, 1);
- wyswietlKoszyk();
- }
- function zmienIlosc(index, element){
- produkt[index].ilosc = element.value;
- wyswietlKoszyk();
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement