//***Free for use without any attribution //***Originally posted by Nicke on #javascript //***Cleaned up/changed by Gavin Kistner /********************************************************************************* Parameters: frm - a form object or the name of the form excludeNames - a single string, array of strings, or space-delimited list specifying names of form elements NOT to include in the query string (optional) preventCache - append a unique value to the end of the query string (opt) Returns a string with the form's name/value pairs to be used as a query string Examples:
-or- location.href="foo.html?"+BuildQueryString('myForm',['hidden1','hidden2'],true); **********************************************************************************/ function BuildQueryString(frm, excludeNames, preventCache ){ if (typeof(frm)=="String") frm = document.forms[frm]; if (frm==null || frm.elements==null) return; if (typeof(excludeNames)=="String") excludeNames=excludeNames.split(' '); if (excludeNames){ for (var i=0,len=excludeNames.length;i0?'&':'')+'nocache='+(new Date())*1; return qs; } /********************************************************************************** NOTE1: The name property of a form element is NOT escaped, just the value. NOTE2: Perhaps for historical reasons (in DOM Level 0, the image type input element was not addressable as an object), you cannot reference an image type input element through the Level 0 referencing scheme of document.formName.inputName. Nor do these controls show up in the collection returned by a form's elements property. The exception to this is IE/Mac, which does allow such references, so dont use image input type elements in your forms !!! NOTE3: Unlike using a real form, this script will return name/value for ALL in your form, not just the one the user clicked on. With this script there is no way to determine which submit button the user used unless you handle the submission as an onclick event from the button itself and handle the query string specifically there. **********************************************************************************/