Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Keep repeated checkbox values when building a query string

AI disclosure: This article and its example were generated by an AI assistant. A filter form often needs to send more than one value under the same key. If both Workshop and Talk are checked, the intended URL might be ?format=workshop&format=talk . One line of JavaScript can quietly erase one value: Object.fromEntries(new FormData(form)) . The form data is not a plain object. It can contain…

When building a query string for a filter form, it's important to keep repeated checkbox values intact. If multiple check boxes are selected under the same key, such as "format", the resulting URL should include all selected values, like ?format=workshop&format=talk. However, converting the form data to a plain JavaScript object using Object.fromEntries(new FormData(form)) can cause one value to overwrite the other, resulting in a loss of data.

To demonstrate this, a static HTML file is provided. It contains three checkboxes labeled "Workshop", "Talk", and "Webinar", all pre-checked. Below the form, there's a button to submit the form and display the results. When the "Show calendar" button is clicked, the expected query string should be format=workshop&format=talk&view=calendar.

After submission, the JavaScript parses the form data and converts it into a query string using URLSearchParams. It also shows the parsed formats array, which should contain both "workshop" and "talk".

The example highlights the difference between using a plain object and an array (getAll) for the "format" key. With a plain object, only the last value is kept, while getAll returns an array of all values. The script also shows that unchecking the checkboxes removes the "format" key from the query string, and that disabled checkboxes like "Webinar" are not sent.

In conclusion, when working with filter forms that have repeated checkbox values, it's crucial to use URLSearchParams and avoid converting form data to a plain JavaScript object, as this can lead to data loss. Always test both cases of multiple selections and no selection to ensure the application behaves as intended.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Black for C++: what if your indentation was your syntax tree?

I recently wrote a line of C++ that took me three passes to read. It was not clever code. It was an ordinary constructor initializer list.

  • Structured indentation aligns with C++ syntax, clarifying code structure.
  • Rules govern line breaks and indentation for readability.
  • Example code demonstrates improved readability with structured indentation.

A Korean indie app market reached 878 services in 5 days. The numbers are about distribution, not building.

Shipping stopped being the hard part. With AI coding tools, a solo builder can put a working web app online in a week that would have taken a small team a quarter two years ago.

  • BlackMango indie app marketplace launched on November 24, 2026
  • Platform lists 878 services in 5 days, including web services, apps, games, PC programs, AI tools
  • Creators submit listings in 1 minute, gain permanent pages with maker stories and coupons

Defending GeoServer against XML injection beyond the patch

Defending GeoServer against XML injection beyond the patch The direct fix for CVE-2026-120705 is a GeoServer or GeoTools update that restores entity resolver protection in the vulnerable WFS parsing…

  • XML injection flaw in GeoServer's WFS GetFeatureById operation
  • Mitigation includes disabling WFS for anonymous users and restricting access
  • Updated GeoServer versions: 2.27.7, 2.28.6, 3.0.2

My Journey with Vibe Coding and Building Apps

I'm 56 years old. I come from a technology background, but not in software programming. I've led technology companies, had one for myself until it went bankrupt, and then I shifted gears and went into…

  • At 56, technology professional with no prior coding experience
  • Discovered Vibe Coding in 2025, struggled initially
  • Built first app using PostgreSQL, GitHub, Netlify, Vercel

More from Saturday, 28 November 2026 →