tags:

views:

46

answers:

2

I'd like to use a "hidden" div that will contain a click-able image link based on a PHP return value.

Can someone please point me to an example? I know there is a name for this but I don't know what it's called.

+1  A: 

Show: (api url)

$("#mybuttondivID").show();

Hide: (api url)

$("#mybuttondivID").hide();

An example:

<html>
<head>
    <title> Show/Hide example</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
</head>
<body>
    <div id="mybuttondiv">
        <a href="http://www.google.com"&gt;&lt;img src="http://www.google.be/intl/en_com/images/srpr/logo1w.png" alt="Google" /></a>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {

            // hide the buttondiv before we do the ajax call
            $("#mybuttondiv").hide();

            //do an ajax request to a php page
            $.ajax({
                type: "GET",
                url: "fetch_data.php",
                success: function (html) {
                    //do something when the response returns
                    // in this case, we make the button visible again
                    $("#mybuttondiv").show();
                },
                error: function (request) {
                    //ajax failed, display button again
                    $("#mybuttondiv").show();
                }
            });
        });
    </script>
</body>
</html>

And here is a link to the jquery $.Ajax help page: http://api.jquery.com/jQuery.ajax/

Peter
Hi Peter, thanks for the answer. I am totally jquery illiterate so is there an example that you can point me to so I can see the code?
John
Updated my answer with an example for what "I think" you want.
Peter
A: 

Maybe you're looking for a combination of .hide(), .show(), .toggle() and/or $.get()?

EDIT: Based on your comment above, maybe this is what you're after:

var hidden = $('#someDiv, #someLink').hide();
$.get('someScript.php', function() {
    hidden.show();
});
Kevin
Hi Kevin, thanks for the answer. I really have no idea what I need. What you posted may be the ticket but I am really jquery illiterate. I'm about ready to just scrap the entire jquery library and do this in straight php.
John
It was a bit unclear exactly what outcome you're after. If this is something that PHP can handle simply, I would definitely recommend it instead of loading the entire jQuery library.
Kevin
Thanks again Kevin. Isn't there supposed to be a success in there somewhere? If there is a success back from the server, I'd like to show the clickable image link.
John