multiple radiobutton values ajax problem

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2008
Posts: 1
Reputation: MistahT is an unknown quantity at this point 
Solved Threads: 0
MistahT MistahT is offline Offline
Newbie Poster

multiple radiobutton values ajax problem

 
0
  #1
May 30th, 2008
Hi

I'm having problem with some radiobuttons. On this page I have two groups of radiobuttons and four textboxes. The code works fine with the first set of radiobuttons, but when I try to add code for the second group it doesn't work.... Here's the code.


JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4. <title>Test</title>
  5. <script type="text/javascript" language="javascript">
  6. var http_request = false;
  7. function makeRequest(url, parameters) {
  8. http_request = false;
  9. if (window.XMLHttpRequest) { // Mozilla, Safari,...
  10. http_request = new XMLHttpRequest();
  11. if (http_request.overrideMimeType) {
  12. // set type accordingly to anticipated content type
  13. //http_request.overrideMimeType('text/xml');
  14. http_request.overrideMimeType('text/html');
  15. }
  16. } else if (window.ActiveXObject) { // IE
  17. try {
  18. http_request = new ActiveXObject("Msxml2.XMLHTTP");
  19. } catch (e) {
  20. try {
  21. http_request = new ActiveXObject("Microsoft.XMLHTTP");
  22. } catch (e) {}
  23. }
  24. }
  25. if (!http_request) {
  26. alert('Cannot create XMLHTTP instance');
  27. return false;
  28. }
  29. http_request.onreadystatechange = alertContents;
  30. http_request.open('GET', url + parameters, true);
  31. http_request.send(null);
  32. }
  33.  
  34. function alertContents() {
  35. if (http_request.readyState == 4) {
  36. if (http_request.status == 200) {
  37. //alert(http_request.responseText);
  38. result = http_request.responseText;
  39. document.getElementById('myspan').innerHTML = result;
  40. } else {
  41. alert('There was a problem with the request.');
  42. }
  43. }
  44. }
  45.  
  46. function get(obj) {
  47. var getstr = "?";
  48. for (i=0; i<obj.childNodes.length; i++) {
  49. if (obj.childNodes[i].tagName == "INPUT") {
  50. if (obj.childNodes[i].name == "Name") {
  51. getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  52. }
  53.  
  54. if (obj.childNodes[i].name == "Email") {
  55. getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  56. }
  57.  
  58. if (obj.childNodes[i].name == "Script") {
  59. if (obj.childNodes[i].checked) {
  60. getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  61. }
  62. if (obj.childNodes[i].name == "Annat") {
  63. getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  64. }
  65. if (obj.childNodes[i].name == "Annat2") {
  66. getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  67. }
  68.  
  69. }
  70. }
  71.  
  72.  
  73. }
  74. makeRequest('get.php', getstr);
  75. }
  76. </script>
  77. </head>
  78. <body>
  79. <h1>Ange namn och epost:</h1> <br />
  80.  
  81.  
  82. <form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform">
  83. Namn: <input type="text" name="Name" value=""><br />
  84. Epost: <input type="text" name="Email" value=""><br />
  85.  
  86. <h1>Rösta på följande:</h1>
  87.  
  88. <h2>Fråga 1: Vilket script språk gillar du bäst?</h2>
  89.  
  90. <input type="radio" name="Script" value="PHP" checked> PHP<br />
  91. <input type="radio" name="Script" value="ASP.NET"> ASP.NET<br />
  92. <input type="radio" name="Script" value="JSP"> JSP<br />
  93. <input type="radio" name="Script" value="AJAX"> AJAX<br />
  94. Annat: <br />
  95. <input id="Annat" type="text" value="" />
  96. <br />
  97. <br />
  98. <input type="radio" name="os" value="MS Windows" checked> MS Windows<br />
  99. <input type="radio" name="os" value="LINUX" > LINUX<br />
  100. <input id="Annat2" type="text" value="" /> <br />
  101.  
  102. <input type="button" name="button" value="Rösta!"
  103. onclick="javascript:get(this.parentNode);">
  104. </form>
  105.  
  106. <br><br>
  107. Dina svar:<br>
  108. <span name="myspan" id="myspan"></span>
  109. </body>
  110. </html>

And here's the php file.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3.  
  4. foreach ($_GET as $key => $value) {
  5.  
  6. echo $key . ' : ' . $value . '<br />';
  7. }
  8. ?>
I would very much appricate some help, since I have not found a solution for this despite hours of googleing...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC