I wonder why I couldn’t find any good example of this:
Inside the function, person is an object and there is correct values and selectedPerson is a global variable. Don’t bother \-signs, that was the way to get those visible here.
document.getElementById(heading).innerHTML="<\p><\strong>" + selectedPerson.name+"<strong><\\p>";
This is not working and neither this inside the html:
<p>
<strong>
<script>document.write(selectedPerson.name);</script>
</strong>
</p>
var selectedPerson;
function person(extra){
var extra_array=extra.split(",");
this.name=extra_array[0];
this.head=extra_array[1];
this.gValue=extra_array[2];
this.weight=extra_array[3];
alert(extra_array[0]+" "+extra_array[1]+" "+extra_array[2] +" "+extra_array[3]);
//alert(this.name" "this.head+" "+extra_array[2] +" "+extra_array[3]);
}
selectedPerson = new person(extra);
console.log("**************************extra-------------->" +extra);
And the question is: How can I use global variable/Object inside the HTML? I would like to know both ways if there is? Alert is working when using array, but not with this.name etc. How can I use syntax selectedPerson.name inside the HTML?
Thank you!
Sami
You are instantiating
new person()withextrawhich isundefined.This will error as you try to
split()it, andundefineddoesn’t have asplitmethod.So
selectedPersonwill beundefinedas the object will fail to to be created.