Difference between revisions of "Passing Values Using Parameters"

From SmartWiki
Jump to: navigation, search
(Passing Parameters to the Link)
Line 1: Line 1:
You can create links using several techniques:
+
Using several techniques you can pass values from one page to another by creating links with parameters.
  
In the context of a [[Portal|portal]] interface by using a link:
+
'''Portal'''
 
* Create a [[Portal]] shortcut and associate the link with that shortcut.
 
* Create a [[Portal]] shortcut and associate the link with that shortcut.
 +
 +
<pre>
 +
/urltopage?variable=@variable@
 +
</pre>
 
   
 
   
In the context of a specific [[Application|application]] by using a [[Custom Field|custom field]]:
+
'''Application'''
* Create a [[Custom Field]] of the type [[Custom Field Type: Display Only – Text or System Object|Display Only – Text or System Object]].  Add the link to that field.
+
* Create a [[Custom Field]] of the type [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] with one of the following.
* Create a [[Custom Field]] of the type [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] with the following. It will display as a button.
+
 
 +
'''Display as button'''
 
<pre>
 
<pre>
 
<input type="button" class=Button value="Button Label" onClick='parent.location.href="/urltopage?variable=@variable@"'/>
 
<input type="button" class=Button value="Button Label" onClick='parent.location.href="/urltopage?variable=@variable@"'/>
 
</pre>
 
</pre>
  
 +
'''Display as hyperlink'''
 +
<pre>
 +
<a href="/urltopage?variable=@variable@">Click Here</a>
 +
</pre>
  
 +
==Parsing Parameters==
  
 +
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 html.
  
 +
<pre>
 +
function getParams() {
 +
var idx = document.URL.indexOf('?');
 +
var params = new Array();
 +
if (idx != -1) {
 +
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
 +
for (var i=0; i<pairs.length; i++) {
 +
nameVal = pairs[i].split('=');
 +
params[nameVal[0]] = nameVal[1];
 +
  }
 +
}
 +
return params;
 +
}
 +
params = getParams();
 +
</pre>
  
 +
Place the second function in the body replacing "field1" with the id of the form field and "parameter1" with the name of the parameter being passed.
  
In either case the link can be web [[URL]] or local '''UNC''' type link.
+
<pre>
+
 
==Passing Parameters Through a Link==
+
<script>
+
 
You can pass values using parameters to another page which has form fields to be pre-populated.  For [[URL]] type links the following syntax would be used:
+
var para1=document.getElementById('field1');
 +
para1.value = unescape(params["parameter1"]);
 +
 
 +
</script>
 +
 
 +
</pre>
  
 +
Repeat for additional fields and values.
  
'''urltopage?Firstname=@firstname@&lastname=@lastname@&email=@email@&address=@address@&address2=@address2@&phone=@phone@&extension=@uphoneext@'''
+
'''&city=@city@&province=@province@&postal=@postalcode@&homephone=@home phone@&companyname=@company name@&employeeid=@employee id@'''
 
  
  

Revision as of 16:34, 7 October 2009

Using several techniques you can pass values from one page to another by creating links with parameters.

Portal

  • Create a Portal shortcut and associate the link with that shortcut.
/urltopage?variable=@variable@

Application

Display as button

<input type="button" class=Button value="Button Label" onClick='parent.location.href="/urltopage?variable=@variable@"'/>

Display as hyperlink

<a href="/urltopage?variable=@variable@">Click Here</a>

Parsing Parameters

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 html.

function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
   }
}
return params;
}
params = getParams();

Place the second function in the body replacing "field1" with the id of the form field and "parameter1" with the name of the parameter being passed.


<script>

var para1=document.getElementById('field1');
para1.value = unescape(params["parameter1"]);

</script> 

Repeat for additional fields and values.



SmartSimple will replace the variable references (@lastname@ etc) with values derived from the current user session.