Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <label for="pozicija">Izaberi poziciju</label>
<select id="pozicija">
  <option value="direktor">Direktor</option>
  <option value="poslovodja">Poslovodja</option>
  <option value="radnik">Radnik</option>
</select>
<br><br><br>
<div id="btn1" class="btn">Povuci podatke sa servera</div>
<div id="output"></div>

              
            
!

CSS

              
                .btn {
  border: 1px solid black;
  padding: 8px;
  display: inline-block;
  background-color:red;
  color:white;
  margine: 0 auto;
  display: block;
  text-align:center;
  cursor: pointer;
  
}
#output {
  font-size: 24px;
  padding: 15px;
  text-align: center;
}
              
            
!

JS

              
                var output = document.getElementById("output");
var btn = document.getElementById("btn1");
var select = document.getElementById("pozicija");

/* deo gde se čuva selectovana opcija iz dropdown-a */
var izborPozicije = "direktor";
select.addEventListener("change", function(){
  izborPozicije = select.options[select.selectedIndex].value;
}) 

/* Event handler na dugmetu */
btn.addEventListener("click", function() {
  /* Čišćenje ekrana */
  output.innerHTML="";
  /* Novi XMLHttpRequest objekat */
  var httpRequest = new XMLHttpRequest();
  /* EventHandler  za ajax request */
  httpRequest.addEventListener("load", function(){
    if (this.status < 400) {
      /* Podaci dobijeni ajaxom */
      var myObj = JSON.parse(this.responseText);
      /* Štampanje samo selektovanih pozicija */
      var izborNiz = myObj.filter(function (obj) {
          return obj.pozicija == izborPozicije;    
      });
       for (let izbor in izborNiz) {
          output.innerHTML += izborNiz[izbor].pozicija + " " + izborNiz[izbor].ime + "<br>";
      }
    } else {
      var greska = new Error("Request failed: " + httpRequest.statusText);
      console.log("Server je OK ali neka greška u transportu");
    }
  }, false);
  /* Otvaranje  konekcije i definisanje parametara */
  httpRequest.open("GET", "https://api.myjson.com/bins/erxi9", true);
  httpRequest.send();
}, false )

              
            
!
999px

Console