How do i pass a parameter to a link in html?

In this article I will explain with an example, how to pass (send) Parameters using HyperLink in HTML.

The HTML HyperLink will be assigned an OnClick event handler and when clicked, the value of the TextBox will be set in the HREF attribute of the HTML HyperLink using JavaScript.

When the HTML Anchor Link is clicked, the TextBox value will be passed to the other Page as QueryString parameter using JavaScript.

HTML Markup

The HTML Markup consists of an HTML TextBox and an HTML Anchor Link.

<input type="text" id="txtName"/>

<a href = "javascript:;">Senda>

Passing (Sending) Parameters using HyperLink in HTML

The HTML Anchor Link is assigned an OnClick event handler and when clicked, the value of the TextBox is set in the HREF attribute of the HTML Anchor Link using JavaScript.

When the HTML Anchor Link is clicked, the TextBox value is passed to the other Page as QueryString parameter.

<a href = "javascript:;" onclick = "this.href='Page2.htm?name=' + document.getElementById('txtName').value">Senda>

Screenshot

How do i pass a parameter to a link in html?

Browser Compatibility

The above code has been tested in the following browsers.

How do i pass a parameter to a link in html?
 
How do i pass a parameter to a link in html?
 
How do i pass a parameter to a link in html?
 
How do i pass a parameter to a link in html?
 
How do i pass a parameter to a link in html?

* All browser logos displayed above are property of their respective owners.

Downloads

Using several techniques, you can pass 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 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.

Syntax:

/urltopage?var1=@variable1@&var2=@variable2@


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


Examples:

Portal

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


Button

  • Create a Read Only - System Variables Custom Field with:
 


Hyperlink

  • Create a Read Only - System Variables Custom Field with:
Click Here

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

Receiving Page

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


Place one of the following second functions within the body just prior to the closing body tag ().


Form Field Population

 


HTML Element Population (eg.

, )

 


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

eg.

var para1=document.getElementById('firstname');

or

var para1=document.getElementById('firstname');


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

See Also

  • Pass Variables To Level 1

Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".

How do you add parameters in HTML?

HTML tag is used to pass the parameters to the object that has been embedded using element. We can use more than one tag within an element in any order, but each tag must contain name and value attribute and should be placed at the start of the content.

How do you pass a href variable in HTML?

href”, append the variable to it (Here we have used a variable named “XYZ”). Then we need to append the value to the URL. Now our URL is ready with the variable and its value appended to it. In the example below, we will append a variable named 'XYZ' and its value is 55.

How do you pass a URL in HTML?

Input URL value Property.
Change the URL of a URL field: getElementById("myURL"). value = "http://www.cnn.com";.
Get the URL of a URL field: getElementById("myURL"). value;.
An example that shows the difference between the defaultValue and value property: getElementById("myURL"); var defaultVal = x. defaultValue;.
How to put a variable in anchor tag

How do you pass a value in HTML?

For sending data to two servelets make one button as a submit and the other as button. On first button send action in your form tag as normal, but on the other button call a JavaScript function here you have to submit a form with same field but to different servelets then write another form tag after first close.