0

i have a link that needs to be triggered from a success post:

<?php    
if ($_POST["action"] == "1") {
?>
<script type='text/javascript'> 
$(window).load(function() {
    $(".likepic").click();
});
</script>
<?php } ?>

<script type='text/javascript'> 
$(window).load(function() {
$(".likepic").click(function(){
    $(".likepic").colorbox({width:"620px", height:"570px", inline:true, href:"#likepic_lightbox"});
});
});
</script>
<a href="#" class="likepic"></a>
<div class="blackk" style="display:none;">
<div id="likepic_lightbox">test
</div>
</div>

so if that post action is 1 then run the jquery script and click on the link for something else to happen :)

this is what i tried but without success.

any ideas? Thanks

1 Answer 1

2

Try using $(document).ready() instead of $(window).load()

Also, you'll need to switch the order of your JavaScript blocks. The click handler needs to be defined first.

Play with a test version here: http://jsfiddle.net/irama/bcMp7/

Or see updated code below:

<script type='text/javascript'> 
    $(document).ready(function() {
        $(".likepic").click(function(){
            $(".likepic").colorbox({width:"620px", height:"570px", inline:true, href:"#likepic_lightbox"});
        });
    });
</script>

<?php if ($_POST["action"] == "1") { ?>
<script type='text/javascript'> 
    $(document).ready(function() {
        $(".likepic").click();
    });
</script>
<?php } ?>


<a href="#" class="likepic"></a>
<div class="blackk" style="display:none;">
    <div id="likepic_lightbox">test</div>
</div>

Let us know how you go!

Sign up to request clarification or add additional context in comments.

7 Comments

i didn't manage to make it work yet, though it seems that should
What's the issue that you're facing now? Any errors in the JS console? Any PHP errors?
no, the script doesn't run, there should be that lightbox popping up... hmmm
Hi @Patrioticcow that sounds like it might be a different issue related to the lightbox (not related to PHP triggering a click event). If you replace the colorbox call with an alert('test') and it pops up, then this question has been answered. Happy to help work through the other issue, but its probably best to start a new question for it.
Hi @Patrioticcow - How'd you go? Let us know if you need any more help with this question. I'm not too familiar with colorbox, but I'm happy to take a look.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.