AnsweredAssumed Answered

Write field into HTML and JavaScript in Webviewer

Question asked by pfroelicher on May 15, 2018
Latest reply on May 17, 2018 by Draco

I have another thread, where I ask the same question here

Read JSON array into ??

 

I have the following HTML, which, in a web viewer displays just nicely some buttons with the JSON that the site viacep supplies.

However, in the URL, inside the <script> tag of JS I would need to exchange "sp" with field contents of "uf" like this

"https://viacep.com.br/ws/"&cep_json_table1::uf&"/"&cep_json_table1::localidade&"/"&cep_json_table1::logradouro

 

I cannot pull that off, so that the web viewer correctly displays the buttons with the options.

I tried to make variables $$begin $$url and $$end and concatenate but

 

 

Follows my HTML with JS, that pulls JSON form the site viacep, makes a list of buttons that the user could choose.

__________________________HTML HERE__________________

<!DOCTYPE html>

<html>

<body>

 

 

<div id="id01"></div>

 

 

<script>

var xmlhttp = new XMLHttpRequest();

var url = "https://viacep.com.br/ws/sp/sao paulo/padre/json";

 

 

xmlhttp.onreadystatechange = function() {

    if (this.readyState == 4 && this.status == 200) {

        var myArr = JSON.parse(this.responseText);

        myFunction(myArr);

    }

};

xmlhttp.open("GET", url, true);

xmlhttp.send();

 

 

function myFunction(arr) {

    var out = "";

    var i;

    for(i = 0; i < arr.length; i++) {

        out += "<button>" + arr[i].logradouro  + " "+

        arr[i].cep + '</button><br>';

    }

    document.getElementById("id01").innerHTML = out;

}

</script>

 

 

</body>

</html>

 

This is the text of the HTML when I create the HTML, pulling the field content into the HTML.. It is, in my opinion the same, minus some formatting.. but this will not display anything..

any hints?

 

________calculated HTML__________

 

<!DOCTYPE html> <html> <body>  <div id="id01"></div>  <script> var xmlhttp = new XMLHttpRequest(); var url =https://viacep.com.br/ws/SP/São Paulo/john/json";  xmlhttp.onreadystatechange = function() {     if (this.readyState == 4 && this.status == 200) {         var myArr = JSON.parse(this.responseText);         myFunction(myArr);     } }; xmlhttp.open("GET", url, true); xmlhttp.send();  function myFunction(arr) {     var out = "";     var i;     for(i = 0; i < arr.length; i++) {         out += "<button>" + arr[i].logradouro  + " "+         arr[i].cep + '</button><br>';     }     document.getElementById("id01").innerHTML = out; } </script>  </body> </html>

Outcomes