
Re: Wait until flag=true before continuing with the procedur
Don't search anymore, the solution has been found on an other forum.
Here is the solutions:
The main problem was "<script type="
text/javascript">".
After that, it was fine tuning, but it work perfectly to set a wait time in the code.
Enjoy!
Code:
<?php
?>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<input type="hidden" id="test_val" value="0" />
<input type="button" id="btn" name="btn" value="start" onclick="check_state(document.getElementById('test_val'), display)" />
<input type="button" id="btn1" name="btn1" value="change" onclick='change_state()' />
<script type="text/javascript">
//________________________________________________________
// Verify the state of a hidden tag and send the next
// procedure when true, else, wait some time
//________________________________________________________
function check_state(variable, other_func){
if (variable.value == 1){
other_func();
} else {
setTimeout(function() {check_state(variable, other_func);}, 500);
}
}
//________________________________________________________
// Change the state of the hidden tag
//________________________________________________________
function change_state(){
document.getElementById('test_val').value = 1 ;
}
//________________________________________________________
// Display when the state of the hidden tag has changed
//________________________________________________________
function display(){
alert('change made');
}
</script>
</body>
</html>