mcfmullen Posted August 28, 2011 Share Posted August 28, 2011 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. For now, my code is just testing to make sure the values are being stored in the first place, into a variable. 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? Here is my form.php: <script language="javascript" type="text/javascript"> <!-- //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); } //--> </script> <form name="myform" action="check.php" method="post"> <fieldset> <legend>Posts</legend> <div id="post_1" class="post"> <b>Post #1</b><br> Content of post #1<br> <p><input type="radio" id="entered" name="like_1" value="like" onclick="ajaxFunction();" onchange="ajaxFunction();" /><label for="like1a">Like</label></p> <p><input type="radio" id="entered" name="like_1" value="dislike" onclick="ajaxFunction();" onchange="ajaxFunction();" /><label for="like1b"> Dislike</label></p> </div> </fieldset> </form> <div id='ajaxDiv'>Your result will display here</div> and this is check.php: <?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; ?> 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? Quote Link to comment https://forums.phpfreaks.com/topic/245846-ajax-radio-buttons-not-storing-values/ Share on other sites More sharing options...
mcfmullen Posted August 28, 2011 Author Share Posted August 28, 2011 FYI, this is my first attempt at ajax so be kind.... For more info: The goal is to have two choices: Like and Dislike for each post in a blog. The value of this choice is to be store in a database so that when the user returns, his choices are recalled into those same radio buttons. The reason? The user can then choose to hide all liked and/or hide all disliked posts. Quote Link to comment https://forums.phpfreaks.com/topic/245846-ajax-radio-buttons-not-storing-values/#findComment-1262723 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.