Changes

Passing Values Using Parameters

1,445 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 in 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 links with a link to the destination page that includes parameterslinking the variables to be passed. These are then parsed by the receiving page back into values. '''Syntax:''':<font size="3">'''/urltopage?var1=@variable1@&var2=@variable2@'''</font>  '''Where:'''* ''urltopage'' is the relative [[URL]] to the destination page.* ''variable1'', ''variable2'' etc. are the variable names (e.g. @firstname@). * ''var1'', ''var1'' corresponding names for the variables   <u>'''Examples:'''</u>
'''Portal'''
* Create a [[Portal]] shortcut and associate the link with that shortcut.
/urltopage?var1=@variable1@&var2=@variable2@
 
'''Button'''
* 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>
'''Application'''
* Create a [[Custom Field]] of the type [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] with one of the following.
 '''Display as buttonHyperlink'''* 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.a href="/urltopage?parameter1var1=@variable1@&var2=@variable2@"'>Click Here</a>
</pre>
'''Display as hyperlinkNote''': User and Company variables can be used to pass the current logged in user details and their company details.<pre><a href="/urltopage?parameter1=@variable1@">Click Here</a></pre>Receiving Page==
==Parsing Parameters==On the receiving page the parameters can pre-populate a form or an HTML element which resides on that page. In order to achieve this the following [[JavaScript]] functions can be used.
On the receiving page the parameters can pre-populate a form which may reside on that page. In order to achieve this the following javascript functions can be used. Place the following first function in the head of the htmlHTML.
<pre>
</pre>
 Place one of the following second function in functions within the body replacing "field1" with just prior to the id of the form field and "parameter1" with the name of the parameter being passedclosing body tag (&lt;/body>).  '''Form Field Population'''
<pre>
var para1=document.getElementById('field1');
var para2=document.getElementById('field2'); para1.value = unescape(params["parameter1var1"]);para2.value = unescape(params["var2"]); 
</script>
</pre>
Repeat for additional fields '''HTML Element Population (eg. &lt;div>, &lt;span>)''' <pre> <script> var para1=document.getElementById('element1');var para2=document.getElementById('element2'); para1.value = unescape(params["var1"]);para2.value = unescape(params["var2"]); </script>  </pre>  Replace "field1" or "element1" etc. with the actual form or element id name and values"var1" with the parameter name. eg. var para1=document.getElementById('firstname'); &lt;input type="text" value="" id="firstname"> or  var para1=document.getElementById('firstname'); &lt;div id="firstname">&lt;/div>  
[[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
687
edits