samhale86 Posted January 10, 2011 Share Posted January 10, 2011 Hi, Need some help please. I have the following function: <script type="text/javascript"> function getVote(int) { 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 (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("ajax").innerHTML=xmlhttp.responseText; } } var questionid = document.question.questionid.value; xmlhttp.open("GET","result.php?id="+questionid+"&vote="+int,true); xmlhttp.send(); } </script> I then have the following onClick: <input type="radio" name="vote" value="1" onClick="getVote(this.value);" /> <input type="radio" name="vote" value="2" onClick="getVote(this.value);" /> Currently, all is good and works perfectly, the div 'ajax' refreshes ajax style with 'result.php' and I can take the value. But what I now need to do is refresh two divs. I have tried everything from putting two onClicks on the radio button, within the 'getVote' function calling in the second function and many more alternatives. The second function is pretty much the same, just a different div ID: <script type="text/javascript"> function getTotal(int) { 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 (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("total").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","total.php?id="+questionid+"&vote="+int,true); xmlhttp.send(); } </script> The problem I have, I think, is that both functions need to use 'xmlhttp.open', and it seems once one has ran, the functions end. Any ideas gratefully received. Thanks. Quote Link to comment Share on other sites More sharing options...
brianlange Posted January 10, 2011 Share Posted January 10, 2011 The ajax function should be able to run more than once. Do you have a url you can post? Quote Link to comment Share on other sites More sharing options...
samhale86 Posted January 10, 2011 Author Share Posted January 10, 2011 PM sent. Thank you. Quote Link to comment 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.