Use select with API in JSON

0

I'm making a web page where I'm using the select tag for different uses of an API that is in JSON ( link ) and an input to enter the information, how can I do an if in javascript with the values of the select and send a POST to parse the JSON in pure javascript?

    
asked by isalvinator 25.11.2017 в 05:21
source

1 answer

0

Good hope this is what you are looking for I put the example in jquery and in javascript vanilla

// jquery

$("#select1").change(function(){
  $.get("https://newton.now.sh/derive/"+$(this).val(), function(data, status){
    
  $("#pre").html(JSON.stringify(data))
    });  
})

// javaScript Vanilla

document.getElementById("select2").addEventListener("change",function(){
    $.get("https://newton.now.sh/derive/"+this.value, function(data, status){
        document.getElementById("pre2").innerHTML = JSON.stringify(data);
});
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>jquery</h2>
<select name="" id="select1">
  <option value="x%5E2">opcion1</option>
    <option value="x%5E5">opcion2</option>
    <option value="x%5E10">opcion3</option>
</select>
<pre id="pre">
  
</pre>
<br><br>
<h2>javascript vanilla</h2>
<select name="" id="select2">
  <option value="x%5E2">opcion1</option>
    <option value="x%5E5">opcion2</option>
    <option value="x%5E10">opcion3</option>
</select>

<pre id="pre2">
  
</pre>
    
answered by 25.11.2017 в 15:53