I have an issue with one of my website.
I have some list links like this:
<ul>
<li><a data-toggle="modal" data-target="#myModal" data-id="10">Room 10</a>
<li><a data-toggle="modal" data-target="#myModal" data-id="20">Room 20</a>
</ul>
On my #myModal
, I want the form appears to edit info. So I passed the data-id
, which is the id into my database.
HTML is the following:
<div class="modal modal-open" id="myModal">
<form class="modal-form form-horizontal">
<div class="modal-header">
<h3>Room #xx</h3>
</div>
<div class="modal-body"> <input name="roomNumber" type="text" value="xx">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
My question, is how can I load the rooms infos from my db into the #myModal
window ?
Step by Step:
- I click on the Edit room link.
- The modal loads infos from the db.
- I can change info.
- I save the form.
- The modal close.
Thanks a lot.
Your Html like this :
Assuming an element in your modal with the ID
roomNumber
, such as:you'd do something like this to populate it:
http://jsfiddle.net/isherwood/Yafb5
There's probably a way to simplify this by grabbing the click target inside the show function and getting the id there, but it's escaping me at the moment.
Update: Found it:
http://jsfiddle.net/isherwood/Yafb5/4