Get URL Parameters and Fill them in a Form Field
How do I make an get url parameters and fill them in a form field?
A few simple lines of Javascript to get the values of parameters from a URL, and fill them into a form field(?event=Event Name). It also decodes URI's to have clean inputs (i.e. no '%20').. What is a get url parameters and fill them in a form field? How do you make a get url parameters and fill them in a form field? This script and codes were developed by Christopher Williams on 28 November 2022, Monday.
Get URL Parameters and Fill them in a Form Field - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Get URL Parameters and Fill them in a Form Field</title> <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.0/css/foundation.min.css'>
</head>
<body> <div class="row">
<p>Sample URL: <br />
<a href="https://codepen.io/itschriswilliams/pen/JWgaRO?event=ACPNY Gala" target="_top">https://codepen.io/itschriswilliams/pen/JWgaRO?event=ACPNY Gala</a> <br />
<a href="https://codepen.io/itschriswilliams/pen/JWgaRO?event=EmblemHealth Annual Sales Meeting" target="_top">https://codepen.io/itschriswilliams/pen/JWgaRO?event=EmblemHealth Annual Sales Meeting</a> </p>
<p>References:<br />
<a href="http://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters" target="_top">http://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters</a>
<br />
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI" target="_top">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI</a> <br />
<a href="http://stackoverflow.com/questions/3221094/target-input-by-type-and-name-selector" target="_top">http://stackoverflow.com/questions/3221094/target-input-by-type-and-name-selector</a>
</p>
<br /> <br />
<form id="event"> <fieldset> <label for="eventInputField">"Hidden" Event Field Targeted by ID</label> <input id="eventInputField" type="text" name="eventInputField" value="" /> <label for="eventInputField2">"Hidden" Event Field Targeted by Name</label> <input id="eventInputField2" type="text" name="eventInputField2" value="" /> </fieldset>
</form>
</div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Get URL Parameters and Fill them in a Form Field - Script Codes JS Codes
$( document ).ready(function() {
// Get the URL & Params, Break them Down
function getUrlVars() { var vars = {}; var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; }); return vars; }
// Get just the event param
var eventID_ENC = getUrlVars()["event"];
// Decode the URI to Plaintext Chars
var eventID = decodeURI(eventID_ENC);
// Write it to the Form Field (js only)
document.getElementById('eventInputField').value = eventID;
// Write it to the Form Field (jquery targeted by name)
$("input[type='text'][name=eventInputField2]").val(eventID); }); //END DOCREADY
Developer | Christopher Williams |
Username | itschriswilliams |
Uploaded | November 28, 2022 |
Rating | 3 |
Size | 2,378 Kb |
Views | 42,504 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Lightweight Responsive YouTube Embed | 1,723 Kb |
Responsive Pricing Chart | 1,825 Kb |
Multi-Column Ordered List | 2,362 Kb |
Half Height Background Color | 2,144 Kb |
Simple Accordion Script using jQuery | 1,478 Kb |
CSS Ghost Button | 2,117 Kb |
Horizontal menu, full width sub menu | 2,073 Kb |
A Pen by Christopher Williams | 22,194 Kb |
Fixed Position Elvis | 1,263 Kb |
Responsive MegaNav | 4,371 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
CSS Dynamic Width Square Div | Elleestcrimi | 2,861 Kb |
Obligatory CSS3 UI Nav | Romandiaz | 9,017 Kb |
Donut Chart example - MorrisJS | Capelo | 2,385 Kb |
Masonry | Uriuriuriu | 5,005 Kb |
Awesome Full Page Menu Nav | Ey_intuitive | 4,194 Kb |
Awesome | Samarthpd | 2,901 Kb |
Custom Checkbox and radio inputs SCSS | Rgfx | 3,367 Kb |
Svg sky | Omodev | 7,070 Kb |
Multiple jCarousel | Pafnuty | 2,461 Kb |
Responsive Section hover effect to show content | Berdejitendra | 2,540 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!