• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

Is it a good practice to make javascript reuseable?

Stalker

Member
Oct 9, 1999
193
0
0
Is it consider a good practice as I am doing validation of input which largely the same for most textfield? My country population largely still use 56K modem.
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
what do you mean by resuseable? do you mean you want to cache a *.js script on their local machine? If so, be aware that Windows will pop up a confirmation if a user tries to run a script which is on the local machine. may be an annoyance you don't want.
 

Stalker

Member
Oct 9, 1999
193
0
0
no not so advance just:

function LengthTextFieldValidator(location,minLength,maxLength)
{
....
if(document.helloform.ID_No)
alert(ID_NO is incorrect)
if ...
alert( ...
if ...
alert(...
}


function validate(){
LengthTextFieldValidator(document.helloform.ID_No,3,20);
LengthTextFieldValidator(document.helloform.Name,5,20);
....
}
 

replicator

Senior member
Oct 7, 2003
431
0
0
It is always good to use reusable code when you are programming.

I can't think of when you would not want your code to be reusable. :)

Your example looks fine.