[Javascript] Making a Inline validation using js DOM and CSS part II

Troy III Ajnej trojani2000 at hotmail.com
Sun Mar 15 10:38:05 CDT 2009


Hi Márcio.

I've just tested it and it works as intended.

I've removed your intermediate function function call, since it doesn't

work that way.

 

It is better to supply your function arguments with the needed IDs

of your elements directly from the event function call where you can

see them.

...

 <label>Idade:
 <input type="text" name="idade" id="idade" onblur="validar('idade', 'erro_idade');" />
 <div class="erro" id="erro_idade">Campo Obrigatorio: Introduza a idade.</div><br />
 </label>

...

 

So you can move your compacted script away from the page,

 

<!--
 function validar(fieldId, errorId) {
   fieldId = document.getElementById(fieldId);
   errorId = document.getElementById(errorId);
  if (fieldId.value == "") {
   errorId.style.display = "inline" }
  else { errorId.style.display = "none"   }
 }
-->

and still preserve a higher level of its readability. 

 

But you'll be needing more code and another (better if) separated 

function for it to become an inteligent form validation function.

 

Regards
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                      Troy III
                         progressive art enterprise
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
> From: talofo at gmail.com
> To: javascript at lists.evolt.org
> Date: Fri, 13 Mar 2009 23:27:34 +0000
> Subject: Re: [Javascript] Making a Inline validation using js DOM and CSS part II
> 
> Thanks. I was really stuck on this. I will test this tomorrow and post back
> the progress and the doubts.
> 
> Thanks a lot,
> Regards,
> Márcio
> 


_________________________________________________________________
Windows Live™ Groups: Create an online spot for your favorite groups to meet.
http://windowslive.com/online/groups?ocid=TXT_TAGLM_WL_groups_032009


More information about the Javascript mailing list