View unanswered posts | View active topics It is currently Wed Dec 13, 2017 2:41 am



Reply to topic  [ 2 posts ] 
 Wait until flag=true before continuing with the procedure 
Author Message
Junior Member

Joined: Wed Feb 08, 2012 10:04 pm
Posts: 2
Post Wait until flag=true before continuing with the procedure
Hello to all.

I've made a javascript function in my php file that reload info inside a <div> tag (using location.replace(..), modify a hidden tag's value and some other process. While doing that, I've discover that the script does not wait until the info is fully loaded in the <div> before executing the rest of the procedure, and this is causing me some problems. I then tried to create a way to have the code to wait until a flag=true before continuing. The idea is great, but I now have a bug in my test file which prevent me from verifying my assumption. It is probably something stupid but I've been on it since the last 3 hours and I can't see it. Chrome and IE keeps telling me that there is a "object expected" on the second <input> tag.
Here's the code

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="javascript:check_stat(document.getElementById('test_val').value, display())" />
<input type="button" id="btn1" name="btn1" value="change" onclick='change_state()' />

<script type="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){
other_func();
} else {
setTimeout('check_state()', 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>


Can anyone help on this.

Thanks.


Wed Feb 08, 2012 11:05 pm
Report this post
Profile
Junior Member

Joined: Wed Feb 08, 2012 10:04 pm
Posts: 2
Post 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>


Thu Feb 09, 2012 12:21 pm
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.