thegleek wrote:
moaiamorfo wrote:

hi thegleek,

if you read my post, you can see that I used the "(1)" as a reference for the code:

<script type="text/javascript">

;)

hi all

yeah yeah.. well regardless,  got it working on my site 100%. so all kudos to you sir :)

glad to hear this, my friend. :)

you can see the script in action here. :)

hi thegleek,

if you read my post, you can see that I used the "(1)" as a reference for the code:

<script type="text/javascript">

;)

hi all

hi all, I'm a brand new newbie. ;)
sorry for my bad English! :P

I used the work of Savvy as inspiration for a math registration check based on a simple sum.
But, in this case, the textfield is disabled and its value can be modified only by clicking on two "+" and "-" buttons: I think (or I hope) that this operation can't be easily do by a bot.

this is the code.

header.php:

locate the line that starts with:

(1)

<script type="text/javascript">

and before it add this line:

<?php $max=10; ?>

this is the maximum value that the two values to be added can reach.
then, after the (1) line, put this:

var max=<?php echo $max; ?>;
var randomValue1=Math.floor(Math.random()*max);
var randomValue2=Math.floor(Math.random()*max);
var theSum=randomValue1+randomValue2;
max*=2;

function upAndDown(the_form, sign){
    var theValue=the_form.elements["mathValue"].value;
    if(sign=="+" && theValue<max) theValue++;
    else if(sign=="-" && theValue>0) theValue--;
    the_form.elements["mathValue"].value=theValue;
}

this is the JavaScript code that generates the sum value and that controls the behavior of the "+" and "-" buttons. put this code before the process_form function.
well, now inside the process_form function, locate the } that close the for and, afer it, put this code:

        if (the_form.elements["mathValue"].value != theSum){
            alert("The sum result is not correct.\nPlease retry.");
            the_form.elements["mathValue"].focus();
            return false;
        }

the work on the header.php file is over.

register.php:

in this file, put the following code in the position you like (according to the div structure):

            <div class="inform">
                <fieldset>
                    <legend>A little math (and antispam) question</legend>
                    <div class="infldset">
                        <p><script type="text/javascript"> document.write('What is the result of '+randomValue1+'+'+randomValue2+'?'); </script></p>
                        <div class="rbox">
                            <input type="button" name="buttonDown" onclick="upAndDown(this.form, this.value);" value="-" /><input type="text" name="mathValue" maxlength="2" size="2" value="0" disabled /><input type="button" name="buttonUp" onclick="upAndDown(this.form, this.value);" value="+" />
                        </div>
                    </div>
                </fieldset>
            </div>

tha's all. :)
I hope this work may be useful for someone: thanks again to Savvy for his great idea. ;)

bye all