Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append values into an existing anchor href

I have captured 3 values from a datalist template using JavaScript, now I need to append these values into an existing anchor which is:

<a id="link" href='nextpage.aspx?id=<%#Eval("PlateId")%>&pp= #Eval("price")%>'>

I found the way to get the anchor href from JavaScript:

<script language='javascript' type="text/javascript" >
    function addLink() { 
        var anchor = document.getElementById("link"); 
        anchor.href = anchor + "&qty=";} 
</script>

But, I can't add the js value after "&qty=", I have tried adding the value like this:

anchor.href = anchor +"&qty=+Value+"

And with this:

anchor.href = anchor +"&qty='Value' "

I can't put it out of the quotation marks, because it won't display in the anchor.

like image 944
Carlos Siles Avatar asked Oct 04 '22 23:10

Carlos Siles


1 Answers

anchor.href = anchor + "&qty="

should be

anchor.href = anchor.href + "&qty="

...otherwise you are trying to turn the link element into a string!

Meanwhile, you still need to keep Value out of the quotation marks, otherwise the final text generated will always be exactly that text: Value. If Value is a variable and is not returning the value you expect (an empty or undefined value, for example), then you need to look at the code that declares it and change that.

like image 192
Barney Avatar answered Oct 13 '22 03:10

Barney