asmodeus94

pomocnikOkienny

Jun 12th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.90 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <style type="text/css">
  6. #main,#result{
  7.     margin:0 auto;
  8.     width:500px;
  9. }
  10. #result{
  11.     margin-top: 20px;
  12. }
  13. #buttons{
  14.     width:500px;
  15.     margin:0 auto;
  16.     text-align:center;
  17. }
  18. </style>
  19. <title>Pomocniczek okienny</title>
  20. </head>
  21. <body>
  22. <div id="main">
  23.     <textarea id="txt" style="width:500px;height:200px;""></textarea>
  24.     <div id="buttons">
  25.         <input id="zP" type="button" value="Zaznacz pole"/>
  26.         <input id="bR" type="button" value="Ogarnij liczby"/>
  27.         <input id="wierszCen" type="button" value="Dodaj wiersz cen"/>
  28.         <select id="coKonkretnie">
  29.             <option value="">Co to jest?</option>
  30.             <option value="0">Cena</option>
  31.             <option value="1">Szerokość</option>
  32.             <option value="2">Wysokość</option>
  33.         </select>
  34.     </div>
  35. </div>
  36. <div id="result">
  37.     <textarea id="txtR" style="width:500px;height:200px;""></textarea>
  38.     <div id="buttons">
  39.         <input id="cP" type="button" value="Czyść pole"/>
  40.     </div>
  41. </div>
  42. <script type="text/javascript">
  43. var d = document;
  44. var sch = "";
  45. function ogarnijLiczby(){
  46.     var ele = d.getElementById('txt');
  47.     var wartosc = ele.value;
  48.     if(wartosc == '' || (wartosc == sch && sch != '')){
  49.         alert('Nie wprowadziłeś nowych danych!');
  50.         return false;
  51.     }
  52.     var selectW = d.getElementById('coKonkretnie');
  53.     if(selectW.value == ''){
  54.         alert('Ale co tam wkleiłeś?');
  55.         return false;
  56.     }
  57.     wartosc = wartosc.replace(/\n/g,' ');
  58.     var przerabiane = '';
  59.     przerabiane = wartosc;
  60.    
  61.     switch(parseInt(selectW.value)){
  62.         case 0:{
  63.             przerabiane = przerabiane.replace(/ /g,';');
  64.             przerabiane += ';~';
  65.         break;}
  66.         case 1:{
  67.             var pojedyncze = przerabiane.split(' ');
  68.             var pary = '';
  69.             var ktZKolei = 0;
  70.             for(var i = 0; i < pojedyncze.length ; i++){
  71.                 ktZKolei++;
  72.                 if(ktZKolei % 2 == 1) pary += pojedyncze[i]+'-';
  73.                 else pary += pojedyncze[i]+';';
  74.             }
  75.             przerabiane = pary;
  76.         break;}
  77.         case 2:{
  78.             przerabiane = przerabiane.replace(/ - /g,'-');
  79.             przerabiane = przerabiane.replace(/ /g,';');
  80.             przerabiane += ';';
  81.         break;}
  82.     }
  83.     ele.value = przerabiane;
  84.     sch = ele.value;
  85. }
  86.  
  87. var buttonLiczby = d.getElementById('bR');
  88. buttonLiczby.onclick = ogarnijLiczby;
  89. dodajWiersz = d.getElementById('wierszCen');
  90. var txt = d.getElementById('txt');
  91. var zaznaczPole = d.getElementById('zP');
  92. zaznaczPole.onclick = function(){
  93.     txt.select();
  94. }
  95. var txtR = d.getElementById('txtR');
  96. dodajWiersz.onclick = function(){
  97.     if(txtR.value.indexOf(txt.value) == -1){
  98.         txtR.value += txt.value;
  99.         txt.value = '';
  100.     }
  101.     else if(txtR.value != '') alert('Już to dodałeś!');
  102. }
  103. txtR.onclick = function(){
  104.     this.select();
  105. }
  106. var czyscPoleZb = d.getElementById('cP');
  107. czyscPoleZb.onclick = function(){
  108.     txtR.value = '';
  109. }
  110. </script>
  111. </body>
  112. </html>
Advertisement
Add Comment
Please, Sign In to add comment