Difference between revisions of "Passing Values Using Parameters"

From SmartWiki
Jump to: navigation, search
Line 24: Line 24:
 
<a href="/urltopage?parameter1=@variable1@&parameter2=@variable2@">Click Here</a>
 
<a href="/urltopage?parameter1=@variable1@&parameter2=@variable2@">Click Here</a>
 
</pre>
 
</pre>
 +
 +
Replace "variable1" with the actual variable name and "parameter1" with a corresponding name (eg. firstname=@firtsname@).
 +
  
  
Line 87: Line 90:
  
  
 +
Replace "field1" or "element1" etc. with the actual form or element id name and "parameter1" with the parameter name.
 +
 +
eg.
 +
 +
<pre>
 +
 +
var para1=document.getElementById('firstname');
 +
&lt;input type="text" value="" id="firstname">
 +
 +
or
 +
 +
var para1=document.getElementById('firstname');
 +
&lt;div id="firstname">&lt;/div>
 +
 +
</pre>
  
 
   
 
   

Revision as of 16:22, 7 October 2009

Using several techniques you can pass values from one page to another in order to pre-populate form fields or display on an HTML page. This is done by creating links with parameters.

Portal

  • Create a Portal shortcut and associate the link with that shortcut.
/urltopage?parameter1=@variable1@&parameter2=@variable2@

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@&parameter2=@variable2@"'/>

Display as hyperlink

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

Replace "variable1" with the actual variable name and "parameter1" with a corresponding name (eg. firstname=@firtsname@).


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


Form Field Population


<script>

var para1=document.getElementById('field1');
var para2=document.getElementById('field2');

para1.value = unescape(params["parameter1"]);
para2.value = unescape(params["parameter2"]);


</script> 


HTML Element Population (eg. <div>, <span>)


<script>

var para1=document.getElementById('element1');
var para2=document.getElementById('element2');

para1.value = unescape(params["parameter1"]);
para2.value = unescape(params["parameter2"]);

</script> 


Replace "field1" or "element1" etc. with the actual form or element id name and "parameter1" with the parameter name.

eg.


var para1=document.getElementById('firstname');
<input type="text" value="" id="firstname">

or 

var para1=document.getElementById('firstname');
<div id="firstname"></div>



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