skopy
August 28, 2022, 11:52am
1
Hi,
i cant figure out the simpliest way of selecting one of the options with the button
here is what i am trying to do, sure i could make 3 modals with default selected but that is just extra code…
https://modaltesting.bss.design/
here is a link to bsdesign
thanks
Like this
On button1 set a data attribute data-option="1"
On button2 set a data attribute data-option="2"
On button3 set a data attribute data-option="3"
add this in a javascript file
(function (document) {
"use strict";
const ready = (callback) => {
if (document.readyState != "loading") callback();
else document.addEventListener("DOMContentLoaded", callback);
};
ready(() => {
const simpleModal = document.getElementById("modal-1");
simpleModal.addEventListener("show.bs.modal", (e) => {
const option = document.getElementById("options");
const button = e.relatedTarget.getAttribute('data-option')
option.value = button
});
});
})(document);
Here is an example
1 Like