When you design a webpage and you want to pre-populate a form with specific values that might change with circumstances, it can be challenging. The script "preset.js" used by this page examines the URL to see if it includes a query string. If so, that query string is used to preset the options in the selection lists in this form. The JavaScript is as flexible as I could make it. Just insert the form name/ID in the function call to "populate()" in an "onload" attribute in the <body> tag of your webpage. The code supports multiple parameters in the query string so that you can preset more than one part of the form. It supports pre-populating text fields, checkboxes, select/option lists and radio buttons.
The sample form below calls this same page with the form data in a query string so that you can see it in action. The query string is displayed above the form so you can see that it changes when you make changes, since the form itself will not seem to change. If you want an acid test, you can manually alter the query string parameters in the address bar of your browser, move the cursor to the end of the resulting URL, and press <RETURN> to call the page with different settings for the form fields.
If you use this code on your website, I'd appreciate it if you would post a link on your site to my scripts page as follows:
<a href="http://www.rainbodesign.com/pub/">Rainbo Design's Tools and Scripts for Webmasters</a>
Click here to return to the Rainbo Design Tools and Scripts menu.
Preset Form software Copyright (C) 2003-2009 by Richard L. Trethewey. All rights reserved.