I´ve come across a script which I need to modify but I don't know how, what I need is to set on page load it reads the value and toss the result that is coming from a database.
The code I will paste is working and does fetch the result from the DB from the select form, now how I can I set a variable that is loaded when page loads and get the result from the DB?
have 3 pages I depend on
1 datalyer page its all good
2 php page
3 html page. here hast the script below, I'm using select option for Peter Griffin his value I will like it to be variable member.
I said onload because on page 1, when ever user surf through the web the pages refresh then new data I send and I need the result of the DB based on the variable.
<script>
/** page one where member is a value that is fetch from a layer
var member = google_tag_manager["GTM-x"].dataLayer.get('ContractNumber');
console.log(member); **/
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
console.log(this.responseText);
}
};
xmlhttp.open("GET","elsewhere.php?q="+str,true);
console.log(str);
xmlhttp.send();
}
}
</script>
<body>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="variable member">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Joseph Swanson</option>
<option value="4">Glenn Quagmire</option>
</select>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>
</body>
as I said before this code is working, but instead of using the select how can I tell it on pageload read the variable X and fetch result, in this case "0000004445" is what I need, the variable will be dynamic so "0000004445" can become anything.