Using Form_CustomValidate during registration

I have set the JavaScript of Other - Registration Page - Form_CustomValidate to be…

function(fobj) { // DO NOT CHANGE THIS LINE!
// Your custom validation code here, return false if invalid.
var $cd = $(this).fields(“code”); // Get a field as jQuery object by field name
if ($cd != ‘1926’)
return this.onError(“You must enter the correct code provided by your club”); // Return false if invalid
return true;

“code” is a database field and I want the registration rejected unless they enter ‘1926’ in the form.
However the registration just goes through normally whatever is entered on ‘code’.
What am I missing?
Thanks

Please press [F12] from your browser, and check from “Console” section whether any Javascript error message.

No error messages in Console.
All well apart from a 404 for favicon.ico which is normal

sclg wrote:

var $cd = $(this).fields(“code”); // Get a field as jQuery object by field name
if ($cd != ‘1926’)

As the comment says, $cd is a jQuery object, you cannot use it as a value, you may use $cd.val() to get the value.

Thanks.
Tried…
var $cd = $(this).fields(“code”); // Get a field as jQuery object by field name
if ($cd.val() != ‘1926’) // Assume cd is a textbox

… but still no luck and no error messages. I’m sure I’m doing something stupid!
S

Trying to debug this, I put an alert in like this…

function(fobj) { // DO NOT CHANGE THIS LINE!
alert(‘Hello’);
var $cd = $(this).fields(“code”); // Get a field as jQuery object by field name
if ($cd.val() != ‘1926’)

… and the alert pops up as you’d expect.
However, if I put the alert after the following line…

function(fobj) { // DO NOT CHANGE THIS LINE!
var $cd = $(this).fields(“code”); // Get a field as jQuery object by field name
alert(‘Hello’);
if ($cd.val() != ‘1926’)

… then it never appears. I don’t understand why!

Try either:
if ($cd != “1926”)

or:
if ($cd.val() != “1926”)

Which one is work?

It doesn’t get far enough to find out which is what I don’t understand.
Test code is…
function(fobj) { // DO NOT CHANGE THIS LINE!
// Your custom validation code here, return false if invalid.
alert(‘hello’);
var $cd = $(this).fields(“code”); // Get a field as jQuery object by field name
alert($cd.val());
alert($cd);
alert(‘done’);
if ($cd.val() != “1926”) // Assume cd is a textbox
return this.onError(“You must enter the correct code provided by your club”); // Return false if invalid

return true;
}

The first alert (hello) fires but the other three never do. I can’t see why a simple assignment…
var $cd = $(this).fields(“code”);
… should stop the code going any further.
I’ve tried it with just one alert at a time but they never fire if they are placed after that line. It’s as if the code stops there!
Debug in ‘console’ shows no errors.