Changes

Passing Values Using Parameters

927 bytes added, 17:39, 20 October 2017
no edit summary
Using several techniques , you can pass values a value (called a Parameter) from one page to another by creating links with parametersin order to pre-populate form fields or display on an HTML page.
==Sending Page==Values can be sent from the initial (sending) page by creating a link to the destination page that includes parameters linking the variables to be passed. These are then parsed by the receiving page back into values. '''PortalSyntax:''':<font size="3">'''/urltopage?var1=@variable1@&var2=@variable2@'''</font>  '''Where:'''* Create a ''urltopage'' is the relative [[PortalURL]] shortcut and associate to the destination page.* ''variable1'', ''variable2'' etc. are the link with that shortcutvariable names (e.g. @firstname@).* ''var1'', ''var1'' corresponding names for the variables
<pre>
/urltopage?parameter1=@variable1@
</pre>
User and Company variables can be used to pass the current logged in user details and their company details.<u>'''Examples:'''</u>
'''ApplicationPortal'''* Create a [[Custom FieldPortal]] of shortcut and associate the type [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] link with one of the followingthat shortcut. /urltopage?var1=@variable1@&var2=@variable2@
'''Display as buttonButton'''* Create a [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] Custom Field with:
<pre>
<input type="button" class=Button value="Button Label" onClick='parent.location.href="/urltopage?parameter1var1=@variable1@&var2=@variable2@"'/>
</pre>
 '''Display as hyperlinkHyperlink'''* Create a [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] Custom Field with:
<pre>
<a href="/urltopage?parameter1var1=@variable1@&var2=@variable2@">Click Here</a>
</pre>
'''Note''': User and Company variables can be used to pass the current logged in user details and their company details.
==Parsing ParametersReceiving Page==
On the receiving page the parameters can pre-populate a form or an html HTML element which resides on that page. In order to achieve this the following javascript [[JavaScript]] functions can be used.
Place the following first function in the head of the htmlHTML.
<pre>
Place one of the following second functions in within the bodyjust prior to the closing body tag (&lt;/body>)
'''Form Field Population'''
var para1=document.getElementById('field1');
var para2=document.getElementById('field2'); para1.value = unescape(params["parameter1var1"]);para2.value = unescape(params["var2"]); 
</script>
'''Form Field HTML Element Population(eg. &lt;div>, &lt;span>)'''
<pre>
<script>
var para1=document.getElementById('field1element1');var para2=document.getElementById('element2'); para1.value = unescape(params["parameter1var1"]);para2.value = unescape(params["var2"]);
</script>
'''HTML Element Population (Replace "field1" or "element1" etc. with the actual form or element id name and "var1" with the parameter name. eg. &lt;div>, &lt;span>)' var para1=document.getElementById('firstname');
<pre&lt;input type="text" value="" id="firstname">
<script>or
var para1=document.getElementById('firstname');
var para2=document.getElementById('lastname');
para1.innerHTML = unescape(params["firstname"]);
para2.innerHTML = unescape(params["lastname"]);
<&lt;div id="firstname">&lt;/scriptdiv>
</pre>
Repeat for additional fields and values.
[[SmartSimple]] will replace the variable references (@lastname@ , etc.) with values derived from the current [[User|user]] session. 
[[Category:JavaScript]]
==See Also==* [[Category:System Management]][[Category:JavaScriptPass Variables To Level 1]]
Smartstaff, administrator
686
edits