Robert Robert - 1 year ago 63
Javascript Question

Chrome extension form input text is blank on submit

I'm trying to build a chrome extension that downloads a bunch of items from links, the main logic is in my

file and I want to be able to specify in which downloads subfolder I'd like to bundle them all but the value of the input field seems to be empty. Here's my code so far


<!doctype html>
<title>Download CVs</title>
<script src="popup.js"></script>
<form id="folderForm">
Subdir of downloads:
<input type="text" id="folder">
<input type="submit" id="download" value="Download CVs">


function bundleItems() {
file: 'download.js'

document.addEventListener('DOMContentLoaded', function() {
var downloadButton = document.getElementById('download');
downloadButton.addEventListener('click', bundleItems);

chrome.extension.onRequest.addListener(function(logs) {
var folder = document.getElementById('folder').value; {{
filename: folder + '/' + log.attachment.filename

I'm sending information from
and everything works if I try to download it in downloads, so I feel posting my
file will be useless. However, if I try to display the
variable, it's empty. I've searched for lots of other posts on the same issue and none of the solutions seem to work for me.

Xan Xan
Answer Source

You cannot submit to a Chrome extension page. There is no web server to process your POST request in this case. Doing so simply reloads the document (clearing your value from the form).

You need to prevent submitting instead, by specifying type="button" for your button.