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

 

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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