diff --git a/pd/nw/dialog_prefs.html b/pd/nw/dialog_prefs.html
index e58a17e1423789baa477bb3a5caa6a11a8793297..78dbd584851917c4bd4879eb2d89712f7ab7add7 100644
--- a/pd/nw/dialog_prefs.html
+++ b/pd/nw/dialog_prefs.html
@@ -642,6 +642,14 @@ function midi_prefs_callback(attrs) {
             .style.setProperty("display", "none");
         document.getElementsByClassName("alsa_midi")[0]
             .style.setProperty("display", "inherit");
+        // For ALSA, we just set the number of ports we want
+        // for input and output. The tcl/tk interface just reused
+        // the first of the "indevs" for this value, so (for now)
+        // we repeat that mistake here...
+        document.getElementById("alsa_in_ports").value =
+            +get_attr("pd-indevs", attrs)[0];
+        document.getElementById("alsa_out_ports").value =
+            +get_attr("pd-outdevs", attrs)[0];
     } else {
         document.getElementsByClassName("midi_devices")[0]
             .style.setProperty("display", "inherit");