I have a web app with a calendar page where users can select days. I want the selected days to be posted to the server which will then render the next page based on the days. In order to do this, I need the calendar I created to be treated as a form. How do I do something like this. I initially was using an AJAX request since I could store the selected days info in an array, but the issue is that an AJAX request does not load a new page. Your input is greatly appreciated!
Asked
Active
Viewed 26 times
1
-
Please insert your code to your question! Without code it's hard to help you. – FZs Dec 30 '18 at 09:00
-
Unfortunately I don't have the code available right now, but essentially I have a calendar that is rendered as a
. Somehow need to send the selected dates (available in an array) in a form submission.
– sawmilld Jan 03 '19 at 13:13
1 Answers
0
var url = "https://example.com/methd";
var date = document.getElementById("calendar");
var keyName = "dates";
date.addEventListener("change", function(e) {
var form = document.createElement("form");
form.setAttribute("method", "POST");
form.setAttribute("action", url);
var inputField = document.createElement('input');
inputField.setAttribute("type", "hidden");
inputField.setAttribute("name", keyName);
inputField.setAttribute("value", this.value);
form.appendChild(inputfield);
document.body.appendChild(form);
form.submit();
});
<input type="date" id="calendar" />

Chirag R
- 36
- 7
-
Oh nice this is pretty dope. So keyName would contain the list of dates? – sawmilld Jan 03 '19 at 13:12