This topic is locked

jscript function to validate a text field

1/2/2009 2:20:56 PM
ASPRunnerPro General questions
E
enfoque_traza author

Hi,
I want to use the function NIF (see code bellow) to validate a text field when adding or editing a record. The field name is 'DN+LETRA'.
I've tried the following code in the "after record added" table events and I've copied the NIF function inside the include/jsfunctions.js file.
It doesn't work: I cannot add any new record. Any suggestion?
Thanks,
=========================

dim DLE
DLE=dict("DNI+LETRA")
if nif(DLE) then

AfterAdd = True

else

Response.Write "Error"

AfterAdd = False

end if

=========================
function nif(dni)

{

if (dni.length!=9)

return false;

numero = dni.substr(0,dni.length-1);

let = dni.substr(dni.length-1,1);

numero = numero % 23;

letra='TRWAGMYFPDXBNJZSQVHLCKET';

letra=letra.substring(numero,numero+1);

if (letra!=let)

return false;

else

return true;

}

J
Jane 1/6/2009

Hi,
to add JavaScript code proceed to the Visual Editor tab, switch to HTML mode and add your code at the end of the page.

Here is a sample:

<script>

function nif(dni)

{

if (dni.length!=9)

return false;

numero = dni.substr(0,dni.length-1);

let = dni.substr(dni.length-1,1);

numero = numero % 23;

letra='TRWAGMYFPDXBNJZSQVHLCKET';

letra=letra.substring(numero,numero+1);

if (letra!=let)

return false;

else

return true;

}

document.forms.editform.value_DLE.onchange=function()

{

if (!nif(document.forms.editform.value_DLE.value))

alert('Error');

}

</script>