louis_coetzee Posted January 12, 2009 Share Posted January 12, 2009 Hi,I am trying to post value with ajax, like I am doing with all the rest of my forms, exept when I echo the value, wether it's checked or unchecked I get exactly the same value. which is "yes" /////////////////////////////////////////////////// register.php My Form <input name="terms" type="checkbox" id="terms" value="yes"> I agree to the <a href="#" target="Terms">Terms Of Use.</a> <br> <input name="legal" type="checkbox" id="legal" value="yes"> I am of legal age to work in South Africa. The Ajax: <script> var url = "registerscript.php"; var what = "RegisterStatus(req.responseText)"; function CheckRegister() { var legal = document.getElementById("legal").value; var terms = document.getElementById("terms").value; DoCallback("answer+"&where="+where+"&other="+other+"&legal="+legal+"&terms="+terms) } function RegisterStatus(Status) { alert(Status); } </script> <script type="text/javascript"> // JavaScript Document function DoCallback(data) { // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = processReqChange; req.open('POST', url, true); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); req.send(data); // branch for IE/Windows ActiveX version } else if (window.ActiveXObject) { req = new ActiveXObject('Microsoft.XMLHTTP') if (req) { req.onreadystatechange = processReqChange; req.open('POST', url, true); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); req.send(data); } } } function processReqChange() { // only if req shows 'loaded' if (req.readyState == 4) { // only if 'OK' if (req.status == 200) { eval(what); } else { alert('There was a problem retrieving the XML data: ' + req.responseText); } } } </script> /////////////////////////////////////////////////////////////////////// registerscript.php function LegalTerms() { extract($_REQUEST); echo $terms; //////////even here the value stays 'yes'//// echo $legal; //////////and here////////////////////////////// if ($terms !== 'yes') { echo 'Please accept terms and confirm that you are of legal age to work in South Africa'; }else { if ($legal !== 'yes') { echo 'Please accept terms and confirm that you are of legal age to work in South Africa'; }else { return true; } } } //////////////////////////the end/////////////////// Please any help would be appreciated. Thanks in advanced. Quote Link to comment https://forums.phpfreaks.com/topic/140564-ajax-checkbox-value-post-problem/ Share on other sites More sharing options...
priti Posted January 13, 2009 Share Posted January 13, 2009 <input name="terms" type="checkbox" id="terms" value="yes"> I agree to the <a href="#" target="Terms">Terms Of Use.</a> <br> <input name="legal" type="checkbox" id="legal" value="yes"> I am of legal age to work in South Africa. Here the value is set to "YES" so you are receivng checkbox value as "yes" all the time. Quote Link to comment https://forums.phpfreaks.com/topic/140564-ajax-checkbox-value-post-problem/#findComment-736114 Share on other sites More sharing options...
louis_coetzee Posted January 13, 2009 Author Share Posted January 13, 2009 I understand that you would think that, but this is the checked value. It's not supposed to stay the same. Quote Link to comment https://forums.phpfreaks.com/topic/140564-ajax-checkbox-value-post-problem/#findComment-736116 Share on other sites More sharing options...
killah Posted January 13, 2009 Share Posted January 13, 2009 I see you are using "South Africa" Are you originated from there? If so can we get in contact? I am from south africa myself. Quote Link to comment https://forums.phpfreaks.com/topic/140564-ajax-checkbox-value-post-problem/#findComment-736132 Share on other sites More sharing options...
Philip Posted January 13, 2009 Share Posted January 13, 2009 You're gathering the value in your JS instead of checking to see if it's checked or not. Instead of .value, you need to use .checked on the checkboxes. Quote Link to comment https://forums.phpfreaks.com/topic/140564-ajax-checkbox-value-post-problem/#findComment-736382 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.