Schrene Posted February 2, 2011 Share Posted February 2, 2011 I am still learning. How would I combine these? Or not repeat "The variable that makes Ajax possible" part of the 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); } Thanks in advance for your help Quote Link to comment https://forums.phpfreaks.com/topic/226486-i-need-help-combining-functions/ Share on other sites More sharing options...
.josh Posted February 4, 2011 Share Posted February 4, 2011 seriously, do yourself a favor and get jQuery or prototype framework or something. Quote Link to comment https://forums.phpfreaks.com/topic/226486-i-need-help-combining-functions/#findComment-1169680 Share on other sites More sharing options...
Schrene Posted February 7, 2011 Author Share Posted February 7, 2011 Ummmmmm yea thanks for the helpful tip As I stated I am still learning. jQuery or prototype framework Trying to accomplish what I want to in something I have never used and know nothing about. Quote Link to comment https://forums.phpfreaks.com/topic/226486-i-need-help-combining-functions/#findComment-1171150 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.