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">×</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?
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.
Just change the button for <a href="#" id="myBtn">Open Modal</a> , your current script will assign the onclick method.
You can use the Bootstrap . modal('show') method for launching the modal window automatically when page load without clicking anything.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With