Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Fancybox (or equiv) from Form input type="submit"

is there a way to get a fancybox (http://fancy.klade.lv/) or any other lightbox from submitting a FORM (with an image button)?

HTML looks like this:

<form action="/ACTION/FastFindObj" method="post">
  <input name="fastfind" class="fastfind" value="3463" type="text">
  <input name="weiter" type="submit">
</form>

These won't do:

    $("form").fancybox();
    $("input").fancybox();
    $("input[name='weiter']").fancybox();

Anyone spotting my mistake or having a workaround or an alternative script? Thanks in advance

like image 341
nickmorss Avatar asked Jun 09 '09 11:06

nickmorss


People also ask

How do I open fancyBox on button click?

jQuery(document). ready(function($) { $('button'). on('click', function() { $. fancybox(); }); });

What is fancyBox in HTML?

fancybox is designed to display images, video, iframes and any HTML content. For your convenience, there is a built in support for inline content and ajax.

How do I know if fancyBox is loaded?

Here is the code: if ($('div#fancybox-frame:empty'). length >0) { alert('it is empty'); $.


1 Answers

I believe all the other answers miss the point of the question (unless I am the one misunderstanding). What I think the author wanted was to have it such that when a form is submitted, its results are displayed in a fancybox. I didn't find that any of the other answers provided that functionality.

To achieve this, I used the jQuery Form Plugin (http://malsup.com/jquery/form/) to easily convert the form to an ajax call. Then I used the success callback to load the response into a fancybox using a manual call to $.fancybox().

$(document).ready(function() {
    $("#myForm").ajaxForm({
        success: function(responseText){
            $.fancybox({
                'content' : responseText
            });
        }
    }); 
});

So instead of attaching fancybox to some artificial <a> tag, you attach ajaxForm to the form itself.

like image 75
Garland Pope Avatar answered Sep 28 '22 15:09

Garland Pope