Jump to content

Ajax checkbox value post problem


louis_coetzee

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/140564-ajax-checkbox-value-post-problem/
Share on other sites

<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.

 

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.