Hi guys,

I have an ideea of doing 3 form validations from one file

The content of the file is

//detalii 1-categorie
var categorie  = new Validator("categorie");
categorie.addValidation("add_categorie","req","Va rugam sa va completati categoria");

//detalii 2-subcategorie
var subcategorie  = new Validator("subcategorie"); 
subcategorie.addValidation("add_subcategorie","req","Va rugam sa va completati subcategoria");

//detalii 3-continut
var continut  = new Validator("continut");
continut.addValidation("add_continut","req","Va rugam sa va completati continutul");

How could I load 1 if I'm on page 1 and 2 if I'm on page 2 and so on ... ?

Any ideas instead of doing 3 separate files ?

I do not understand the question. :( Why are these scripts in separated file? Could you simply put them all in 1 file and then include it using src? The down side is that you would include other variable/data that will not be used in differen pages. Unless you pass a variable to specified which variable you want to be loaded...

//i.e.
var categorie = null
var subcategorie = null
var continut = null
function getValidator(validatorName) {
  if (validatorName=="categorie") {
    categorie = new Validator(validatorName)
    categori.add(...)
  }
  else if (validatorName=="subcategorie") {
    subcategorie = new Validator(validatorName)
    subcategori.add(...)
  }
  else if (validatorName=="continut") {
    continut = new Validator(validatorName)
    continut.add(...)
  }
}

But better yet, use the same variable name instead of 3 variables...

//i.e.
var categorie = null
function getValidator(validatorName) {
  categorie = new Validator(validatorName)
  if (validatorName=="categorie") {
    categori.add("add_categorie","req","Va rugam sa va completati categoria")
  }
  else if (validatorName=="subcategorie") {
    categori.add("add_subcategorie","req","Va rugam sa va completati subcategoria")
  }
  else if (validatorName=="continut") {
    categori.add("add_continut","req","Va rugam sa va completati continutul")
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.