Forum Moderators: open
The best solution to achieve this will depend on what technology you are using. Since you have posed this question in the javascript forum, I'll assume you are using javascript and static html.
1) You must pass the information in the url.
This is done as products.html?product=insurance&priority=cheap
2) You must read the data from the url into the form on the new page.
I wrote the following script a while back to do this.
// Fills a form with parameters passed by url.
// The standard format is //..../page.html?name1=value1&name2=value2
// Parameters that are not recognised are ignored.
// Parameter names must correspond with element names in the form.
// Names are NOT case sensitive.
// Values are not case sensitive but case is preserved for text fields.
// To set or clear a checkbox, use name=1 or name=0 respectively.
// To set a radiogroup value, use name=value where value is the value of the button to be checked.function loadParam(f,p) // f is a form, p is a string : 'name=value'
{ var pa = p.split('='); if (pa.length < 2) return false;var n = pa[0].toLowerCase();
var v = pa[1].toLowerCase();
with (f) {
for (var i = 0; i < length; i++) with (elements[i]) {
if (n == name.toLowerCase()) {
var tp = type.toLowerCase();
if (tp == 'select-one') {
for (var j = 0; j < length; j++) if (options[j].text.toLowerCase() == v) {
selectedIndex = j;
break;
}}
else if ((tp == 'radio') && (value.toLowerCase() == v)) checked = true
else if (tp == 'checkbox') checked = ((v!= '') && (v.charAt(0)!= '0'))
else value = pa[1]
}}
}}function loadParams(f) // f is a form
{ var tmp = unescape(document.location.search); if (tmp.charAt(0) == '?') tmp = tmp.substring(1);if ((typeof(f) == 'undefined') ¦¦ (tmp == '')) return false;
tmp = tmp.split('&'); for (var i = 0; i < tmp.length; i++) loadParam(f,tmp[i]);
}loadParams(document.forms[0]);
Place this code in a filed called readparams.js
At the bottom of the page, add <script src="readparams.js" type="text/javascript"></script>
Naturally, there are other solutions.
Kaled.
if this is in the destination form:
<td class="plan_option" align="left" nowrap><input type="radio" name="plan" value="RES1T"> RES 1T</td>
I have tried ...&plan=RES1T no luck
here is the page I am trying to populate:
<Sorry, no personal URLs.
See Terms of Service [webmasterworld.com]>
What do you think?
[edited by: tedster at 8:44 pm (utc) on May 8, 2005]
Ideally, since you are using php, this should be done server-side, but the script above should work unless there is more than one form on the page. However, I haven't tested this with input elements nested in tables.
A couple of other comments
1) You should wrap radio buttons and checkboxes within <label></label> tags so that the user can click the text.
2) When verifying, I prefer to see all incorrect items highlighted rather than each generating an individual alert.
Kaled.
* It is now - I moved the thread.
[edited by: tedster at 11:27 pm (utc) on May 8, 2005]