I'm using the following javascript code to collect data from a form via javascript and then send the var's to a php script and return the data to the same page via ajax, All is working fine at the moment.
I use the following button code in my html web page.Code://Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var pollname = document.getElementById('pollname').value; var pollid = document.getElementById('pollid').value; for(i=0; i<document.getElementById('freepoll').optionselect.length; i++){ if(document.getElementById('freepoll').optionselect[i].checked){ var optionselect = document.getElementById('freepoll').optionselect[i].value; } } var wpm = document.getElementById('wpm').value; var sex = document.getElementById('sex').value; var queryString = "?pollname=" + pollname + "&pollid=" + pollid + "&click=" + click + "&optionselect=" + optionselect + "&wpm=" + wpm + "&sex=" + sex; ajaxRequest.open("GET", "ajax-poll.php" + queryString, true); ajaxRequest.send(null); }
What i want to do is add a second submit button to the html page and have the javascript send 1 var to the php script if submit1 is clicked and another var if submit2 is clicked. All the other var's sent via the form will remain the same regardless of which button is clicked, i just need to let the php script know which submit button was pressed.HTML Code:<input type="button" onclick="ajaxFunction()" id="click" value="vote">
Thanks for your help
Chris.



Reply With Quote


Bookmarks