Change header color 🎲 🎲

Jake Paris

in Maine, in 2024

Fill form fields based on url query parameters

Based on this code I did earlier, I created this function which fill out form fields based on the query parameter values. There are three optional parameters.

Using with no parameters will automatically try to match the parameter names in the url with form field names. Maybe dangerous?

fillFieldsFromParams()

The first parameter specifies which form field to fill in. Using only the first parameter will attempt to fill the field with a parameter of the same name.

fillFieldsFromParams('email');

The second parameter specifies which query parameter to get the value from.

fillFieldsFromParams('email','emailInUrl');

The third parameter limits the auto-form-filling action to a specific form. Provide a css selector to indicate which form to target:

fillFieldsFromParams('email','emailInUrl','#contact-form');

See the Code