I'm making a fake horoscope website as a little project and am having some trouble with this last functionality. Currently, the user puts in their date and birthplace and some other info, then hitting the submit button calls a function which parses the date info and makes an alert pop up with a different paragraph depending on which astrological sign they are. This works fine, but isn't pretty.
Instead, I'd rather the submit button causes a modal to pop up and that same paragraph appears there (again, depending on what they'd changed the date input to).
I'm very new to HTML and JavaScript, so all of the "pass data into a modal" questions I've read have answers that just go over my head or don't seem to apply, as far as I can tell. Here's the HTML I have currently. I've cut out some of the extraneous inputs that don't actually do anything other than not allow submission until they're filled out and the paragraphs which are just long strings:
<body>
<header>
</header>
<main>
<div id="zodiacModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="zodiacModalTitle" class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Where I need the paragraph</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<form class="needs-validation" onsubmit="test(); return false;" novalidate>
<div class="form-row">
<div class="col-sm mb-3">
<label for="birthdate">Birthdate</label>
<input id="birthdate" class="form-control" type="date" value="2000-01-01" required>
</div>
</div>
<div class="form-group">
<div class="form-check">
<input id="terms" class="form-check-input" type="checkbox" value="" required>
<label class="form-check-label" for="terms">
I believe.
</label>
<div class="invalid-feedback">
You must believe before submitting.
</div>
</div>
</div>
<button class="btn btn-primary" type="submit">Submit Form</button>
</form>
</main>
<script>
function test()
{
// Declare and initialize variables with strings for each sign here
var date = document.querySelector("#birthdate").value.slice(5).split("-");
var month = parseInt(date[0], 10), day = parseInt(date[1], 10);
var signs = ["", capricorn, aquarius, pisces, aries, taurus, gemini, cancer, leo, virgo, libra, scorpio, saggitarius, capricorn];
var days = [0, 20, 19, 20, 20, 21, 21, 22, 22, 23, 23, 22, 21];
alert((day > days[month]) ? signs[month + 1] : signs[month]);
}
</script>
From the documentation, it looks like I need to change the submit button to something like this:
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#zodiacModal">
TL;DR: I want to replace the alert that pops up on submitting the form (which has a different paragraph in the body depending on date input) with a modal that does the same thing. Any noob-friendly explanations of what I need to do here would be really appreciated.