Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX radio buttons don't work
    text
    copied!<p>Alright so I have a pair of radio buttons that are to store their values into a database in order to retain their state when the user returns to the site in the future. The thing is, whether the user chooses button 1 (like) or button 2 (dislike) the value is always returned as like. Can anyone help me figure out why dislike isn't being returned?</p> <p>Here is my form.php:</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; &lt;!-- //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 entered = document.getElementById('entered').value; var queryString = "?entered=" + entered; ajaxRequest.open("GET", "check.php" + queryString, true); ajaxRequest.send(null); } //--&gt; &lt;/script&gt; &lt;form name="myform" action="check.php" method="post"&gt; &lt;fieldset&gt; &lt;legend&gt;Posts&lt;/legend&gt; &lt;div id="post_1" class="post"&gt; &lt;b&gt;Post #1&lt;/b&gt;&lt;br&gt; Content of post #1&lt;br&gt; &lt;p&gt;&lt;input type="radio" id="entered" name="like_1" value="like" onclick="ajaxFunction();" onchange="ajaxFunction();" /&gt;&lt;label for="like1a"&gt;Like&lt;/label&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="radio" id="entered" name="like_1" value="dislike" onclick="ajaxFunction();" onchange="ajaxFunction();" /&gt;&lt;label for="like1b"&gt; Dislike&lt;/label&gt;&lt;/p&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;div id='ajaxDiv'&gt;Your result will display here&lt;/div&gt; </code></pre> <p>and this is check.php:</p> <pre><code>&lt;?php // Retrieve data from Query String $entered = $_GET['entered']; // Escape User Input to help prevent SQL Injection $entered = mysql_real_escape_string($entered); echo $entered; ?&gt; </code></pre> <p>So basically $entered is only storing "like" no matter which radio button is selected and changing the selection should change the value stored, but that doesn't happen either. Am I missing something?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload