How to Concatenate a Variable for a Hyperlink

Concatenate a string with a hyperlink

value = value + "<a href="' + s + '"> Read More</a>" This is indeed invalid. You have two extra ' outside, they should be inside.

Should be value = value + "<a href='" + s + "'> Read More</a>";

Or in ES6 :

value = `${value}<a href='${s}'>Read More</a>`;

Concatenate URL with variable in C#

_configuration["MY_BASE_URL"] is a configuration variable which returns your base URL i.e http://mytestsite.com/users/, now you need to append variable value to it then hard coded string /theRestOfTheUrl.

Instead of writing everything inside _configuration key, write it with string interpolation

Try

string url = $"{_configuration["MY_BASE_URL"]}{variableName}/theRestOfTheUrl";
Console.WriteLine(url); // http://mytestsite.com/users/1234/theRestOfTheUrl

Your code will look like

variableName = "1234";

....

string url = $"{_configuration["MY_BASE_URL"]}{variableName}/theRestOfTheUrl";
var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);

POC: .net Fiddle

How concatenate a PHP variable into a HTML link?

Try the following:

<a class="btn btn-primary" href="../../../paginaIniziale/sceltaModificaAffidatario.php?idCantiere=<?php echo $idCantiere ?>Continua -></a>

What this does is the following:

  1. opens <?php tags so we can write php.
  2. echo your variable in the html template
  3. Close the php by ?>

When you use echo in php it will output the value of a variable to the actual HTML file that will be produced. Thus you use echo when you need to output something dynamic into the html.

How do you concatenate a string with a variable/pass to link?

Your return value is getting discarded. You need to set the href property of window.location.

 <script type="text/javascript">
function set_href() {
var code = "otrta://code?id=" + document.getElementById("textbox1").value;
window.location.href = code;
}
</script>

--

<input type='submit' onclick='set_href()'>

Concatenate a String and <a href=""></a>

If you really need to do that, you'd use a React Fragment (or any wrapper element, like a span), like this:

const example = <>Hello I'm a string<a href="/link">And this is a link</a></>;

Or with the older more verbose syntax:

const example = <React.Fragment>Hello I'm a string<a href="/link">And this is a link</a></React.Fragment>;

Later where you want to use that within another component, you'd use a JSX expression, for instance:

return <div>{example}</div>;

Live Example:

// The Stack Snippets version of Babel is too old
// for <>...</> syntax.
function Example() {
const example = <React.Fragment>Hello I'm a string<a href="/link">And this is a link</a></React.Fragment>;

return <div>{example}</div>;
}

ReactDOM.render(<Example/>, document.getElementById("root"));
<div id="root"></div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.13.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.0/umd/react-dom.production.min.js"></script>

How to concatenate values from a variable in href attribute of anchor tag using golang



Related Topics



Leave a reply



Submit