I am trying to display a div on submitting a form. It displays the div on submitting the form whereas form is not submitted. Here POST method is used. JavaScript is used to display the div.
html file:
<form method="POST" name="myFirstForm" id="chform">
{% csrf_token %}
<input type="hidden" name="details_id" value="{{details.id}}"/>
<input type="hidden" name="details_user_id" value="{{details.user_id}}"/>
<input type="hidden" name="user_id" value="{{user.id}}"/>
<input type="submit" class="btn btn-danger" id="chat" onclick="return myFunction()" value="Chat Now">
</form>
<div class="page-content page-container" id="page-content" style="display:none"></div>
JavaScript:
<script>
document.forms['myFirstForm'].addEventListener('submit', function(event) {
// Do something with the form's data here
this.style['display'] = 'none';
event.preventDefault();
});
function myFunction() {
var x = document.getElementById("page-content");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
views.py:
if request.method=='POST':
jid = request.POST.get('details_id')
print(jid)
cjid = request.POST.get('details_user_id')
print(cjid)
userid = request.POST.get('user_id')
print(userid)
If I not want to display the div and removes JavaScript code , POST method works.Can anyone suggest a solution to solve this issue?