Skip to content

Commit 962c951

Browse files
committed
Fix TypeError occurring when submit.js is on a page w/o a form
1 parent 3982454 commit 962c951

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

submit.js

+29-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
/*jshint esversion: 6 */
22
(() => {
3-
document.querySelector('#submit-button').onclick = () => {
4-
const name = document.querySelector('#speaker-name').value;
5-
const bio = document.querySelector('#speaker-bio').value;
6-
const title = document.querySelector('#talk-title').value;
7-
const abstract = document.querySelector('#talk-abstract').value;
3+
const button = document.querySelector('#submit-button');
4+
if (button) addSubmitButtonListener();
85

9-
const subject = `[workshop proposal] ${title}`;
10-
const body = `Hi Program Committee,` +
11-
`\n\n` +
12-
`I would like to submit a talk proposal for the W3C Workshop on Web and Machine Learning.` +
13-
`\n\n` +
14-
`Name: ${name}` +
15-
`\n\n` +
16-
`Bio: ${bio}` +
17-
`\n\n` +
18-
`Talk title: ${title}` +
19-
`\n\n` +
20-
`Talk abstract: ${abstract}`+
21-
`\n\n` +
22-
`Best regards,\n${name}`;
6+
function addSubmitButtonListener() {
7+
document.querySelector('#submit-button').onclick = () => {
8+
const name = document.querySelector('#speaker-name').value;
9+
const bio = document.querySelector('#speaker-bio').value;
10+
const title = document.querySelector('#talk-title').value;
11+
const abstract = document.querySelector('#talk-abstract').value;
2312

24-
window.location.href =
25-
'mailto:[email protected]' +
26-
'?subject=' + encodeURIComponent(subject) +
27-
'&body=' + encodeURIComponent(body);
28-
};
13+
const subject = `[workshop proposal] ${title}`;
14+
const body = `Hi Program Committee,` +
15+
`\n\n` +
16+
`I would like to submit a talk proposal for the W3C Workshop on Web and Machine Learning.` +
17+
`\n\n` +
18+
`Name: ${name}` +
19+
`\n\n` +
20+
`Bio: ${bio}` +
21+
`\n\n` +
22+
`Talk title: ${title}` +
23+
`\n\n` +
24+
`Talk abstract: ${abstract}`+
25+
`\n\n` +
26+
`Best regards,\n${name}`;
27+
28+
window.location.href =
29+
'mailto:[email protected]' +
30+
'?subject=' + encodeURIComponent(subject) +
31+
'&body=' + encodeURIComponent(body);
32+
};
33+
}
2934
})();
3035

0 commit comments

Comments
 (0)