简体   繁体   中英

Calling Colorbox with function call but it closes as soon as it opens

What i am doing is calling a Function passval() that itself is calling another function menu() that displays colorbox iframe

<html>
<head>
<link rel="stylesheet" href="colorbox/colorbox.css" />
<script src="js/jquery.min.js"></script>
<script src="colorbox/jquery.colorbox.js"></script>
<script>
            $(document).ready(function(){
                //Examples of how to assign the ColorBox event to elements

                $(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
                $(".inline").colorbox({inline:true, width:"40%"});
                $(".iframe").colorbox({iframe:true, width:"90%", height:"80%"});

            });
            </script>


    <script type="text/javascript">
    function passval()
    {

    var vc = document.getElementById('vc').value;
    var fc = document.getElementById('fc').value;
    //checking inputs
    //document.write(fc+" ");
    //document.write(vc+" ");
    //document.getElementById('inline').click();
    menu();
    }
    function menu() 
    {
      $('<a />').colorbox({fixedWidth:"500px", fixedHeight:"300px", iframe:true, href:"search.php", bgOpacity:0, open:true}); return false;
     }

    </head>
    <body>
    <form id="form1" name="form1" method="post">
    <input type="submit" value="Submit" onclick="passval()" />
    </form>
    <a class='iframe' id="inline" href="chart.htm">iFrame</a>
    </body>
    </html>

But it opens and closes as soon as it was opened.. same is up with click [ document.getElementById('inline').click(); ] called by the function

Any suggestions over it?

You need preventDefault() on your submit click. Now your page is reloaded OR change:

<input type="button" value="Submit" onclick="passval()" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM