Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

How to make a href dynamic

Hi Experts,

I have the following code.
<div>
    <a  href="\join?lang=fr-CA" id="btnReset">@T("Reset")</a>
    <a  id="btnApply">@T("Apply")</a>
</div>

Open in new window


Is it possible to make this href dynamic? An input hidden field "CultureLanguage"  contains the language. If it is "En" then I want the URL to be "\join?lang=EN". Otherwise \join?lang=fr-CA.
I am using C# and MVC

Thanks in advance.
Avatar of David Favor
David Favor
Flag of United States of America image

"\join" will fail subtly in many ways. Use "/join" instead.

Everything you mentioned above is doable + this will all be done in Javascript, if you're trying to make your <div> change in realtime, without a server trip.

You'll load all your language abbreviations (very little memory required), then just update the link in the <div> using JQuery (for best cross browser support).
ASKER CERTIFIED SOLUTION
Avatar of hilltop
hilltop
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Thank you for trying to help me! I just modified your solution little bit and it is working.
 <a href="" id="btnReset">@T("Reset")</a>

 jQuery(document).ready(function () {
if (jQuery("html").attr("lang") == "fr-CA") {
            jQuery("#btnReset").attr("href", "/join?lang=fr-CA");
else {
            jQuery("#btnReset").attr("href", "/join");
        }
)};

Open in new window