Note that there are some explanatory texts on larger screens.

plurals
  1. POmagnific-popup passing a variable
    text
    copied!<p>I'm trying to make <a href="http://dimsemenov.com/plugins/magnific-popup/" rel="noreferrer">magnific popup</a> contain some forms. I would like to pass variables through the html anchor to the final popup. As <strong>Var1</strong> in this pseudocode:</p> <pre><code>&lt;!-- HTML launcher element --&gt; &lt;a href="#test-popup?Var1=X" class="open-popup-link"&gt;Show inline popup&lt;/a&gt; &lt;!-- Popup itself --&gt; &lt;div id="test-popup"&gt; &lt;form method="post" action=""&gt; &lt;input type="hidden" id="myVar" name="Var1" value="[placeholder]" /&gt; &lt;input type="submit" /&gt; &lt;/form&gt; &lt;/div&gt; &lt;!-- Inizialization --&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('.open_popup_link').magnificPopup({ type:'inline', midClick: true, function() { **Here some magic code that sets Var1 = X ** $('#myVar').attr('value', function(i, attr){ return attr.replace('[placeholder]', Var1); });} }); }); &lt;/script&gt; </code></pre> <p>I need this because I will generate serverside (w. PHP) the launchers so that each link will generate different form data.</p> <p>edit: One approach i thought at was to use custom attributes in the launcher, eg:</p> <pre><code>&lt;a href="#test-popup" data-var1="X" class="open-popup-link"&gt;Show inline popup&lt;/a&gt; </code></pre> <p>But I couldn't really get the right jQuery syntax for nesting the attributes processing INSIDE the magnific-popup inizialization. My js/jquery knowledge is very basic, so thank you for any hint.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload