Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use an anchor tag to open a modal page?

Tags:

html

I have an anchor tag in my navbar which I'd like to use to open up a modal form as a helper page. I have used the default W3Schools modal form just to test it it works. However nothing opens, I know it has something to do with the href. But i'm just not sure how to point the href to a modal form.

HTML:

 <div class="collapse navbar-collapse" id="PageNavigation">
                        <ul class="nav navbar-nav" id="NavigationLinks">
                            <li>@Html.ActionLink("DASHBOARD", "Index", "Dashboard", "", new { @class = "MainNavText", @id = "MainNavDashboard" })</li>
                            <li>@Html.ActionLink("EXPORT", "Index", "Dashboard", "", new { @class = "MainNavText", @id = "MainNavExport" })</li>
                            <li><a data-target="#myModel" data-toggle="modal" class="MainNavText" id="MainNavHelp">HELP</a></li>
                         </ul>
                        @Html.Partial("_LoginPartial")
                    </div>

  <div id="myModal" class="modal fade" role="dialog">
        <div class="modal-dialog">

            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Modal Header</h4>
                </div>
                <div class="modal-body">
                    <p>Some text in the modal.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>

        </div>
    </div>

How can I do this?

like image 215
Andrew Kilburn Avatar asked Jul 06 '15 15:07

Andrew Kilburn


People also ask

How do you call a modal in a tag?

You can display bootstrap modal using data attribute (data-toggle, data-target) in anchor tag. You have to use bootstrap CDN in your HTML page in which you want to use the bootstrap modal.

How do I open modal pop on href onclick?

Just change the button for <a href="#" id="myBtn">Open Modal</a> , your current script will assign the onclick method.

How can I open modal pop without click button?

You can use the Bootstrap . modal('show') method for launching the modal window automatically when page load without clicking anything.

How do you trigger a modal link?

Just replace "Your link text" with what you want the link to say, and paste the modified modal trigger link into your website. Unlike the JavaScript for your modal form, you should paste the modified modal trigger link where you want it to appear on your website. NOTE: Modal trigger links are now each their own link.


1 Answers

Found it.

<li>
    <a data-target="#myModal" data-toggle="modal" class="MainNavText" id="MainNavHelp" 
       href="#myModal">HELP</a>
</li>

Just needed to set the id to the href.

like image 81
Andrew Kilburn Avatar answered Sep 18 '22 00:09

Andrew Kilburn