• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Is it a good practice to make javascript reuseable?

Stalker

Member
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.
 
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.
 
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);
....
}
 
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.
 
Back
Top