Difference between revisions of "Passing Values Using Parameters"

From SmartWiki
Jump to: navigation, search
Line 28: Line 28:
 
==Parsing Parameters==
 
==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.
+
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. Place the following first function in the head of the html.
  
 
<pre>
 
<pre>
Line 46: Line 46:
 
</pre>
 
</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.
+
 
 +
Place the following second functions in the body.
 +
 
 +
'''Form Field Population'''
  
 
<pre>
 
<pre>
Line 58: Line 61:
  
 
</pre>
 
</pre>
 +
 +
 +
'''Form Field Population'''
 +
 +
<pre>
 +
 +
<script>
 +
 +
var para1=document.getElementById('field1');
 +
para1.value = unescape(params["parameter1"]);
 +
 +
</script>
 +
 +
</pre>
 +
 +
 +
 +
 +
 +
  
 
Repeat for additional fields and values.
 
Repeat for additional fields and values.

Revision as of 16:57, 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?parameter1=@variable1@

User and Company variables can be used to pass the current logged in user details and their company details.


Application


Display as button

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

Display as hyperlink

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


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. 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 following second functions in the body.

Form Field Population


<script>

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

</script> 


Form Field Population


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