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. Show 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 Browser Compatibility The above code has been tested in the following browsers.
* 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 PageValues 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@
Portal
/urltopage?var1=@variable1@&var2=@variable2@
Click Here Note: User and Company variables can be used to pass the current logged in user details and their company details. Receiving PageOn 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 |