views:

879

answers:

1

Hi,

I'm trying to make a script that automatically starts uploading after the data has been enter in the database(I need the autoId that the database makes to upload the file).

When I run the javascript the scripts runs the php file but it fails calling the other php to upload the file.

too much recursion
setTimeout(testIfToegevoegd(),500); 

the script that gives the error

send("/projects/backend/nieuwDeeltaak.php",'deeltaakNaam='+f.deeltaaknaam.value+'&beschrijving='+
                        f.beschrijving.value+'&startDatum='+f.startDatum.value+'&eindDatum='+f.eindDatum.value
                        +'&deeltaakLeider='+f.leiderID.value+'&projectID='+f.projectID.value,id);

                    function testIfToegevoegd(){

                        if(document.getElementById('resultaat').innerHTML == "<b>De deeltaak werd toegevoegd</b>"){
                            //stop met testen + upload file 

                            document.getElementById('nieuwDeeltaak').target = 'upload_target';
                            document.forms["nieuwDeeltaak"].submit()
                        }else{
                            setTimeout(testIfToegevoegd(),500);
                        }

                    }

                    testIfToegevoegd();

sorry for the dutch names we have to use them it is a school project.

when I click the button that calls all this for a second time (after the error) it works fine.

+15  A: 
setTimeout(testIfToegevoegd(),500);

should be

 setTimeout(testIfToegevoegd,500);

you have to pass the function itself, not its result

stereofrog
Thank your very much
Ken