I have a JavaScript variable I grabbed from a form field and I am trying to use it for the href = value in a link. What is the proper way to output this JavaScript variable in HTML?
-
1You should really provide some code.user188654– user1886542012-06-24 02:00:38 +00:00Commented Jun 24, 2012 at 2:00
-
@holodoc What? Why? His question explains the issue perfectly well.david– david2012-06-24 02:01:16 +00:00Commented Jun 24, 2012 at 2:01
-
2Because so many things are missing in his description like if he is trying to use inline JavaScript or perform the manipulation after the document (or at least DOM) has been loaded, is he using a framework or pure JavaScript, did he even try something before posting etc. etc. etc.user188654– user1886542012-06-24 02:04:23 +00:00Commented Jun 24, 2012 at 2:04
-
I agree with @holodoc. OP should show what they've tried. Can't tell what the actual issue is right now,user1106925– user11069252012-06-24 02:04:29 +00:00Commented Jun 24, 2012 at 2:04
-
2@david: Don't be obtuse. I've answered a lot more questions than you have on StackOverflow, and have seen plenty of times where OP excluded relevant code, only to discover when it was finally included that everything was correct but for a single important and very relevant detail. Instead of giving foolish examples as though they had comparable merit, you should encourage OP to provide detailed information.user1106925– user11069252012-06-24 02:20:42 +00:00Commented Jun 24, 2012 at 2:20
|
Show 7 more comments
3 Answers
Update the href value via javascript. Using something like jQuery it is as simple as:
var link = "www.google.com";
$("a").attr("href", link);
4 Comments
Gregg
I am answering a question. If the OP doesn't like it he can choose to not mark it as the answer. Regarding the variable I created, that was to mimic whatever variable he might have grabbed from his form element.
Gregg
Then feel free to provide your own answer.