hi
I want to create a function that works when a button is clicked inside my form.
I created a function with java script and placed it inside the javascript section in the events of the form.
everything is working till it goes to the line in the javascript which want to call the function again: "function()".when it reaches this line the form disappears from the screen.
I saw that it happens also when a setTimeout (javascript function) is being called.
can't I make calls to the same function from a function?
by the way,when I added another simple function (only an alert inside it),the form crashed immediately when I clicked the button.
Gilad
I want to create a function that works when a button is clicked inside my form.
I created a function with java script and placed it inside the javascript section in the events of the form.
everything is working till it goes to the line in the javascript which want to call the function again: "function()".when it reaches this line the form disappears from the screen.
I saw that it happens also when a setTimeout (javascript function) is being called.
can't I make calls to the same function from a function?
by the way,when I added another simple function (only an alert inside it),the form crashed immediately when I clicked the button.
Gilad
Hi giladl1,
What error messages do you see in the JavaScript Console of your browser web developer tools?
What is the script you are running?
Bob
What error messages do you see in the JavaScript Console of your browser web developer tools?
What is the script you are running?
Bob
what do you mean by: "JavaScript Console of your browser web developer tools" ?
where is it?
the script:
where is it?
the script:
var milisec=9
var seconds=3
var minutes=1
window.addEvent('domready', function() {
$('submit').addEvent('click',function(){
var count=10;
alert(count);
document.getElementById("d2").value='30'
alert("44");
display();
});
function display(){
<!--change the minutes by the seconds: -->
if (seconds<=0){
seconds=59
minutes-=1
}
<!--change the seconds by the milisec: -->
if (milisec<=0){
milisec=9
seconds-=1
}
else
milisec-=1
if(minutes==0 && seconds==0){
document.d.d2.value="time is finished.dial the number:"
td1.innerHTML=""
td2.innerHTML="time is finished.dial the number:"
clearTimeout(myvar)
var list=document.getElementById("d");
list.removeChild(list.childNodes[0]);
document.removeChild(d);
}
else{
document.getElementById("d2").value=minutes+":"+seconds+"."+milisec
display();
alert("yes");//this alert works during running
var myvar=setTimeout("display()",100)//here is the crush line
}
}
Hi giladl1,
Your script is pretty buggy, there are unclosed brackets, undefined variables and possibly some missing semi-colons.
In most current browsers F12 or Ctrl+Shift+i will open the web developer tools.
Bob
Your script is pretty buggy, there are unclosed brackets, undefined variables and possibly some missing semi-colons.
In most current browsers F12 or Ctrl+Shift+i will open the web developer tools.
Bob
about the console-I found the error console.there was something like a jquery error there.I'm not sure if it has any connection to the code here.
after I fixed the code,I tried some experiments:
1. calling recursively to the function display()-worked fine
2. putting setTimeout() function with an alert inside-it worked strange: because of the 3 secs delay,
I had to wait some time after the "before" alert that comes before it ,and then,after I clicked on the
"after" alert ,I could see the "hello" alert which was inside the setTimeout.if I didn't wait and just clicked the "after" alert ,the form was closed and I couldn't see it.
3. putting setTimeout() function with a recursive call to the funtion display()-didn't work at all.
the code now looks like that:
so,how can I make the setTimeout funtion work well ,which means to call the display() function?
after I fixed the code,I tried some experiments:
1. calling recursively to the function display()-worked fine
2. putting setTimeout() function with an alert inside-it worked strange: because of the 3 secs delay,
I had to wait some time after the "before" alert that comes before it ,and then,after I clicked on the
"after" alert ,I could see the "hello" alert which was inside the setTimeout.if I didn't wait and just clicked the "after" alert ,the form was closed and I couldn't see it.
3. putting setTimeout() function with a recursive call to the funtion display()-didn't work at all.
the code now looks like that:
window.addEvent('domready', function() {
$('submit').addEvent('click',function(){
var count=10;
alert(count);
document.getElementById("d2").value='30'
alert("44");
var milisec=9;
var seconds=3;
var minutes=1;
display();
});
function display(){
alert("milisec "+ milisec);
<!--change the minutes by the seconds: -->
if (seconds<=0){
seconds=59;
minutes-=1;
}
<!--change the seconds by the milisec: -->
if (milisec<=0){
milisec=9;
seconds-=1;
}
else
milisec-=1;
if(minutes==0 && seconds==0){
document.d.d2.value="time is finished.dial the number:";
td1.innerHTML="";
td2.innerHTML="time is finished.dial the number:";
clearTimeout(myvar);
var list=document.getElementById("d");
}
else{
document.getElementById("d2").value=minutes+":"+seconds+"."+milisec;
alert("before");
//***************************************************
//*********************the options I tried:**********
//***************************************************
var myvar=setTimeout("display()",100);//doesn't work
//display();//work well
//setTimeout(function(){alert("Hello")},3000);//work only if I wait a little before click the "after" //alert that comes next line:
alert("after");
}
}
so,how can I make the setTimeout funtion work well ,which means to call the display() function?
Hi giladl1,
I'm sorry but it's not practical to provide a JavaScript debugging service here for snippets that aren't particularly linked to ChronoForms. This code still has unclosed brackets and undefined variables. And I have no idea what it it supposed to do - except that it has something to do with timing something.
Bob
I'm sorry but it's not practical to provide a JavaScript debugging service here for snippets that aren't particularly linked to ChronoForms. This code still has unclosed brackets and undefined variables. And I have no idea what it it supposed to do - except that it has something to do with timing something.
Bob
I don't think you should help me with debugging.
I wanted to know if there is a chance that chronoforms doesn't support the setTimeout function.
for me it's ok even if this function has only an alert inside but it will work recursively.
thanks
Gilad
I wanted to know if there is a chance that chronoforms doesn't support the setTimeout function.
for me it's ok even if this function has only an alert inside but it will work recursively.
thanks
Gilad
Hi Gilad,
ChronoForms doesn't do anything to block the setTimout function (or any other JavaScript function) if that is what you are asking.
Bob
ChronoForms doesn't do anything to block the setTimout function (or any other JavaScript function) if that is what you are asking.
Bob
after some thinking,maybe you are right and the problem is with the brackets.so lets make it simple.
I need to add a javascript event which calls to a javascript funtion,which afterwards calls itself,and I need to know where to put the brackets and how will it look ("}" or "};" etc ).
so the code will look like that(as you can see it doesn't have a code,and I put bracket2-two times where I thought it can optionally be,and I didn't know how it should look):
the difference between this and the simple example you added of how to add a javascript to a chronoform is the event and the calling to a function.without it I wouldn't need help.
thanks a lot
Gilad
I need to add a javascript event which calls to a javascript funtion,which afterwards calls itself,and I need to know where to put the brackets and how will it look ("}" or "};" etc ).
so the code will look like that(as you can see it doesn't have a code,and I put bracket2-two times where I thought it can optionally be,and I didn't know how it should look):
window.addEvent('domready', function() {//bracket 1
$('submit').addEvent('click',function(){//bracket 2
//////////////////////
/////do something////
/////////////////////
display();
});//bracket 1
})//bracket 2
display(){
//////////////////////
/////do something////
/////////////////////
setTimeout(display(),100);
}//end display
});//bracket 2
the difference between this and the simple example you added of how to add a javascript to a chronoform is the event and the calling to a function.without it I wouldn't need help.
thanks a lot
Gilad
Hi giladl1,
Here's a version that gets an OK result from JSLint
The closing bracket 2 can go in either place but it's neater and probably more useful to leave the display function definition outside the window.addEvent function.
I have no idea if this will actually work.
Bob
Here's a version that gets an OK result from JSLint
window.addEvent('domready', function () {//bracket 1
$('submit').addEvent('click', function () {//bracket 2
//////////////////////
/////do something////
/////////////////////
display();
});//bracket 1
});//bracket 2
function display() {
//////////////////////
/////do something////
/////////////////////
window.setTimeout(display, 100);
}//end display
There are quite a few changes from your version!The closing bracket 2 can go in either place but it's neater and probably more useful to leave the display function definition outside the window.addEvent function.
I have no idea if this will actually work.
Bob
This topic is locked and no more replies can be posted.