I am still learning.
How would I combine these?
Or not repeat “The variable that makes Ajax possible” part of the code.
[code]function showID(){
var idRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
idRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
idRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
idRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
idRequest.onreadystatechange = function(){
if(idRequest.readyState == 4){
var idDisplay = document.getElementById('color_id');
idDisplay.innerHTML = idRequest.responseText;
}
}
var color = document.getElementById('color').value;
var queryString = "?color=" + color;
idRequest.open("GET", "colorfil_data_color_id.php" + queryString, true);
idRequest.send(null);
}
function showName(){
var nameRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
nameRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
nameRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
nameRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
nameRequest.onreadystatechange = function(){
if(nameRequest.readyState == 4){
var nameDisplay = document.getElementById('color_name');
nameDisplay.innerHTML = nameRequest.responseText;
}
}
var color = document.getElementById('color').value;
var queryString = "?color=" + color;
nameRequest.open("GET", "colorfil_data_color_name.php" + queryString, true);
nameRequest.send(null);
}
function showNum(){
var numRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
numRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
numRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
numRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
numRequest.onreadystatechange = function(){
if(numRequest.readyState == 4){
var numDisplay = document.getElementById('color_num');
numDisplay.innerHTML = numRequest.responseText;
}
}
var color = document.getElementById('color').value;
var queryString = "?color=" + color;
numRequest.open("GET", "colorfil_data_color_num.php" + queryString, true);
numRequest.send(null);
}[/code]
Thanks in advance for your help ;D