I have a php function which ends with a refresh of the page and then throws a javascript function declared:
<script>
var u = null;
function tab(u) {
$('#element1').css('display', 'block');
$('#element2').css('display', 'none');
}
</script>
<?php
if (isset($_POST['submit1'])) {
$tab = 1;
header("Refresh:0");
echo "<script>window.scrollTo(0, 1000);</script>";
echo "<script>tab(".$tab.");</script>";
}
?>
The function of window.scrollto works, but the tab function not. I wrote ob_start and ob_end_flush to avoid headers problems.
You are missing a closing )
on the if statement. Try this:
<script>
var u = null;
function tab(u) {
$('#element1').css('display', 'block');
$('#element2').css('display', 'none');
}
</script>
<?php
if (isset($_POST['submit1'])) {
$tab = 1;
header("Refresh:0");
echo "<script>window.scrollTo(0, 1000);</script>";
echo "<script>tab(".$tab.");</script>";
}
?>
The header("Refresh:0");
shoudn't be a problem as you said. In the worst case you will get an warning saying Warning: Cannot modify header information - headers already sent by...
.
Also, in development you should always have error_reporting
turned on to be able to see the possible errors or warnings. You can turn on error reporting like this:
error_reporting(E_ALL);
ini_set('display_errors', 1);
Don't forget to remove/comment that on production/live.