0

I am stuck on CS50W's Project 3 Mail. I'm very new to JavaScript so I think I'm probably missing something obvious but I cannot get it to send an email. When I go to the admin section there's nothing there so it's not saving anything. I've tried many different things, but just can't get it to actually send the email.

inbox.js relevant code:

function compose_email() {

  // Show compose view and hide other views
  document.querySelector('#emails-view').style.display = 'none';
  document.querySelector('#compose-view').style.display = 'block';

  // Clear out composition fields
  document.querySelector('#compose-recipients').value = '';
  document.querySelector('#compose-subject').value = '';
  document.querySelector('#compose-body').value = '';

}

function load_mailbox(mailbox, template) {

document.querySelector('#compose-form').onsubmit = () => {
fetch('/emails', {
  method: 'POST',
  body: JSON.stringify({
    recipients: document.querySelector('#compose-recipients').value,
    subject: document.querySelector('#compose-subject').value,
    body: document.querySelector('#compose-body').value
  })
})
.then(response => response.json())
.then(result => {
  load_mailbox('sent',template);
});
return false;
}}

inbox.html (relevant code)

  <div id="compose-view">

       <h3>New Email</h3>
       <form id="compose-form">
            <div class="form-group">
                From: <input disabled class="form-control" value="{{ request.user.email }}">
            </div>
            <div class="form-group">
                To: <input id="compose-recipients" class="form-control">
            </div>
            <div class="form-group">
                <input class="form-control" id="compose-subject" placeholder="Subject">
            </div>
            <textarea class="form-control" id="compose-body" placeholder="Body"></textarea>
            <input type="submit" class="btn btn-primary"/>
        </form>
     </div>

    <divid="emails-view">
    </div>

{% endblock %}

{% block script %}
    <script src="{% static 'mail/inbox.js' %}"></script>
{% endblock %}
1
  • Your load_mailbox function runs in an infinite loop. Also, I think that instead of writing a new function, you, by mistake, erased all the code that was previously given for the load_mailbox function in the zipped inbox.js – Vsjain Feb 11 at 6:51

You must log in to answer this question.

Browse other questions tagged .