Hi, I have an ajax function which sends the value to a php form, i am trying to send another value with this but when i try and join the string it will not work. This is the origianl: var infoStr = "?choice="+nVal; AdminRequest.open("GET", "update-file.php"+infoStr, true); Code (markup): This is what i have done: var infoStr; infoStr = "?choice="+nVal; infoStr = infoStr + "&test="; infoStr = infoStr + document.getElementById['test'].value; AdminRequest.open("GET", "update-file.php"+infoStr, true); Code (markup): Cheers, Adam
Here is the whole script before i have done anything to it. var AdminResponse = ""; function parseResponse(field){ var nText = AdminResponse.getElementsByTagName('optionText'); var nVal = AdminResponse.getElementsByTagName('optionVal'); document.forms["register_account"].elements[field].options.length = 1; for (i=0; i<nText.length; i++) { var nOption = document.createElement('option'); var isText = document.createTextNode(nText[i].firstChild.data); nOption.setAttribute('value',nVal[i].firstChild.data); nOption.appendChild(isText); document.forms["register_account"][field].appendChild(nOption); } } function update(nVal, field){ var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); AdminRequest.onreadystatechange = function() { if (AdminRequest.readyState == 4) { if (AdminRequest.status == 200) { AdminResponse = AdminRequest.responseXML; parseResponse(field); } else { alert('Error update-course.php File '+ AdminRequest.statusText); } } } var infoStr; infoStr = "?choice="+nVal; AdminRequest.open("GET", "update-file.php"+infoStr, true); AdminRequest.send(null); } Code (markup):
infoStr = "?choice="+nVal+"&test="+document.getElementById('test').value; HTML: Actually this should work...try it with the replacement above...
what i tend to do with params is often hold them into an array instead. eg: var params = []; params.push("choice=" + nVal); params.push("test=" + document.getElementById("test").value); // ... more var url = "/update-file.php?" + params.join("&"); Code (javascript): this gives you increased readability and also allows you to loop and clean up parmas via things like escape, encodeURI etc. a more advanced version would be to use objects with key: value into the array with a .map callback that joins them. make sure you compose the URL _after_ they click submit so it picks up the right values.