0

I am stuck with something which I cannot figure out and might need some assistance, I'm not an expert in JS

I have a JSON being formatted based on the click of a radio button and this works perfectly fine

http://jsfiddle.net/8kdraw9L/

I then took up this piece of code and included this in my main html I get the below in the console and the function doesn't work as well

Uncaught TypeError: Cannot read property 'value' of null

http://jsfiddle.net/8kdraw9L/1/

I'm probably missing out on something

<script>
var element = document.getElementById("urls").value;
var obj = JSON.parse(element);
var rad = document.querySelectorAll('.radio');
for (var i = 0; i < rad.length; i++) {
    rad[i].addEventListener('change', function() {
        selection = this.value

        obj["response"]["headers"] = {
        "Content-Type": selection
    }
        document.getElementById("urls").innerHTML = JSON.stringify(obj, undefined, 4);
    });
}
<script>
  • @CertainPerformance - I happened to see this question earlier before I could post my question and I didn't get much of a solution by trying out the different options there unless you wish to have me corrected ! – qatestprofile Sep 11 '19 at 06:36
  • Options 1, 3, and 4 of the linked top answer will work just fine for you. – CertainPerformance Sep 11 '19 at 06:38

0 Answers0