Dynamic event handler onfocus() onblur() Javascript profesional needed

I have created a custom validation function, actually I have something like this :

<asp:textbox id='yo' runat='server' />
<script language='javascript'>
function checkCtrlyo(){

this works wondefull the function executes and shows(or not) a custom popup. Please keep in mind that the javascript code is generated automatically, then if I have a second textbox something like this will be generated:

<asp:textbox id='yoTheSecond' runat='server' />
<script language='javascript'>
function checkCtrlyoTheSecond(){

Validate is the generic function who does the validation. I have simplified everything a little, the validate function receives plenty of parameters. Now I need to catch the postback from the button on the page and validate the textboxes, now as the code is generated I do something like this:


function HandleButtons(){
    for(var i=0; i<document.forms.length; i++){
          for(var j=0;j<f.length;j++){
                   theglobal = false;
                   c.onclick=function(){return Cold_Validateall();};

function Cold_Validateall(){
         var tempy=true;
         for(var i=0;i<document.forms.length;i++){
               for(var j=0;j<f.length;j++){
                      if(c.type=='text' || c.type=='textarea'){
                      if (theglobal==false){tempy=false;}}}}
 return tempy;}

If you analyze those functions, I dynamically attach the function Validateall to all the buttons in the web page. The function Validateall simply do a loop on the controls of the page and tries to do a focus and blur of all the textboxes to activate the Validate of the control, then inside the validate I have theglobal var who it's putted to false if the validation was wrong.

now this should work, but in fact it doesn't :( if I have 3 boxes, only the last one is taken into consideration, if the first validates false and the 2 others true, then the postback happens, if the last textbox is false, then the postback is stopped...

Also under firefox, the onfocus and onblur provokes some strange error, I have readed that is a bug of firefox when using onblur and onfocus. but this is not the matter.

Now in short and in resume, I need a dynamic way to activate the validate function of each textbox and if any of them returns false, then stop the postback.

Thank you for the help.
Who is Participating?
Closed, 250 points refunded.
Site Admin
DrakecoldwinterAuthor Commented:
the code seems to work under firefox, but not under Ie :(

I need a way to cancel the postback if one of the controls is not okay
DrakecoldwinterAuthor Commented:
I can feel the bug...
I have a public var called global, then on the buttons on the blur I call ValidateControl and if the control is not okay, then I set global to false, then I do this :

loop each control{
 focus, then blur, then look the global var

then thing is, it looks like Ie is able to do focus, then blur and then test the global var before the validate function sets it to false... :( even more, I have several controls, so it must be able to loop all the controls (and thus have always global=true) before any of then has the chance of setting the var to false :( there is a detail that maked me think this, I putted an alert after the blur to check global, and with the alert everything works... :(

help ?
DrakecoldwinterAuthor Commented:

Ignore everything abobe, read this

Oki, lets try this otherwise, the full points go to the one who tells me how to execute and get the value of the function. validatecontrol returns true or false, how can I provoke and execution and get the true or false result. keep in mind this, if I do toto.onblur(); I will execute but I don't get the result (true or false) so I really need a way to get the result.

<input type='text' name="toto" onblur="validatecontrol('str','*@*.*','failed',100,20)">

DrakecoldwinterAuthor Commented:
well, I have found a solution by myself, is kind of not very elegant, but it works. I have managed to do a javascript array, and I fill on the server side page generation the array with the parameters that normally I use on validatecontrol function, then on my validateall function I simply take this array and cycle on it passing the parameters to Validatecontrol and like that I validate all the controls on the page. It works well.

I will close the question here then.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.