/************************************************************************** * The JS required to make the page function * * Note: * It seems that i cannot reference an external js file from within this file * for some reason, so the generic js function buildQueryStringByFormId had to * be included in this file. * Note that in order to be able to place multiple polls on a single page, * all the js variables and functions must be dynamically named, in this case * by appending the pollId to the declaration and all its subsequent uses. *************************************************************************/ /** * @desc: This method will allow you to get all your form fields in ONE magical step! * right before your ajaxObj.call statement all you have to do is: var form_vars = ajaxObj.getForm('formid'); * that will loop through the form id you pass, and put all the form variables into your query string! * @param: string The ID of the form you wish to submit * @author: http://www.litfuel.net/mybic * @return: string An encoded query string, ready to send to the serve */ function buildQueryStringByFormId421(formId) { var formobj = document.getElementById(formId); var fields = new Array(); var form_len = formobj.elements.length; for (var x = 0; x < form_len; x++) { switch(formobj.elements[x].type) { case 'select-one': if (formobj.elements[x].selectedIndex > 0) { fields.push(encodeURIComponent(formobj.elements[x].name)+'='+encodeURIComponent(formobj.elements[x].options[formobj.elements[x].selectedIndex].value)); } break; case 'select-multiple': var obj = formobj.elements[x]; for(var y=0; y < formobj.elements[x].options.length; y++) { if(formobj.elements[x].options[y].selected) { if(formobj.elements[x].options[y].value == ''){ fields.push(encodeURIComponent(formobj.elements[x].name)+'='+encodeURIComponent(formobj.elements[x].options[y].text)); } else { fields.push(encodeURIComponent(formobj.elements[x].name)+'='+encodeURIComponent(formobj.elements[x].options[y].value)); } } } break; case 'radio': if(formobj.elements[x].checked) { fields.push(encodeURIComponent(formobj.elements[x].name)+'='+encodeURIComponent(formobj.elements[x].value)); } break; case 'checkbox': if(formobj.elements[x].checked) { fields.push(encodeURIComponent(formobj.elements[x].name)+'='+encodeURIComponent(formobj.elements[x].value)); } break; default: // text, password, textarea, etc fields.push(encodeURIComponent(formobj.elements[x].name)+'='+encodeURIComponent(formobj.elements[x].value)); break; } } var new_qstring = fields.join("&"); return new_qstring; } /** * Initalise site variables * @author: http://drnicwilliams.com/2006/11/21/diy-widgets/ (originally) */ // url of remote directory for XSS var BASE_URL421 = "http://minipoller.coredata.com.au/public/"; // url of page to display dynamic survey form var CONTENT_URL421 = BASE_URL421 + "renderer.php?showResults=0&pollId=421"; // id of div tag to dynamically alter the contents of var ROOT421 = 'my_xss_magic421'; /// /// Create a div tag for displaying this minipoll portlet content /// document.write(""); /** * Script to perform the remote content XSS. Heavily modified from original example code. * @author: http://drnicwilliams.com/2006/11/21/diy-widgets/ (originally) */ MyXssMagic421 = new function() { /** * Show the portlet for the miniform in the specified mode * @param string mode - whether to show the input form, or the results * @param string inputString - the string returned by a dynamic form postback */ this.init = function(inputValues) { /** * @desc: Method to show the initial survey questions, or voting results, as appropriate. * @author: D.Holborow * @version: 1.0 2007/04/07 */ this.serverResponseShowPortlet = function(data) { // if no data retrieved, abort if (!data) { return; } // get the destination form element to place the new content from the remote server var div = document.getElementById(ROOT421); // assign new HTML into #ROOT div.innerHTML = data; // make element visible div.style.display = 'block'; // make element visible div.style.visibility = 'visible'; } /// /// Stage 1: Perform the request for remote portlet content /// requestContent(inputValues); /// /// Stage 4: Write out a no-script warning /// var no_script = document.getElementById('no_script'); if (no_script) { no_script.style.display = 'none'; } } /** * Request the content to display */ function requestContent( inputValues, local ) { var script = document.createElement('script'); // How you'd pass the current URL into the request // script.src = CONTENT_URL + '&url=' + escape(local || location.href); //script.src = CONTENT_URL; script.src = CONTENT_URL421 + "&" + inputValues; // IE7 doesn’t like this: document.body.appendChild(script); // Instead use: document.getElementsByTagName('head')[0].appendChild(script); } } /** * Initialise the XSS tool * @author: http://drnicwilliams.com/2006/11/21/diy-widgets/ (originally) */ MyXssMagic421.init(""); /** * @desc Post the dynamic form back and display the results to the user * @author D.Holborow * */ function postPortletForm421(formValues) { // Show the outcome of any user input etc: MyXssMagic421.init(formValues); } function viewBy421(viewBy) { // should be showing postcode specific content var formValues = "pollId=421&viewBy=" + viewBy + "&saveSubmission=0"; // Show the outcome of any user input etc: MyXssMagic421.init(formValues); } /* function viewByPostcode421(formValues) { // should be showing postcode specific content var formValues = "pollId=421&viewBy=POSTCODE&saveSubmission=0"; // Show the outcome of any user input etc: MyXssMagic421.init(formValues); } function viewByNation421(formValues) { // should be showing overall nation results var formValues = "pollId=421&viewBy=NATION&saveSubmission=0"; // Show the outcome of any user input etc: MyXssMagic421.init(formValues); } function viewByElectorate421(formValues) { // should be showing overall nation results var formValues = "pollId=421&viewBy=NATION&saveSubmission=0"; // Show the outcome of any user input etc: MyXssMagic421.init(formValues); } */ function toPollingRoom421(pollId) { window.location = "http://minipoller.coredata.com.au/public/pollingroom.php?pollId=" + pollId; }