JavaScript / HTML help

Status
This thread has been locked.

Dann

Managing Director @ PebbleHost
Supreme
Feedback score
49
Posts
867
Reactions
762
Resources
0
Hello all,
I'm wondering if anyone knows if its possible to add a var from a JavaScript into a href link
Currently something like this works
<span id="price_val"></span>

I'm wanting something like this to work where it has the same variable but within a link
<a href="gid= id=price_val" >Test 123</a>

If you need me to explain it a bit better, Ill try Just ask.
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Shaun

Web Developer, owner of Syncore LLC
Supreme
Feedback score
20
Posts
622
Reactions
408
Resources
0
So what I'm understanding is that the current <span> method just displays an output from a JS script however it's not a clickable link and you want to make it a clickable link?
 

Dann

Managing Director @ PebbleHost
Supreme
Feedback score
49
Posts
867
Reactions
762
Resources
0
So what I'm understanding is that the current <span> method just displays an output from a JS script however it's not a clickable link and you want to make it a clickable link?
Yep, it needs to be able to be within a href link,
So the final link would be like
mc-market.org?{output}
mc-market.org?gid=2
 

Shaun

Web Developer, owner of Syncore LLC
Supreme
Feedback score
20
Posts
622
Reactions
408
Resources
0
That nearly got me there,
I've got the one var in a .js file, For that you've linked me how would i get the var from the .js file into a new var on the html file?

I'm not quite following what you mean here, are you trying to display the var from the JS file as an element on the HTML document?
 

Dann

Managing Director @ PebbleHost
Supreme
Feedback score
49
Posts
867
Reactions
762
Resources
0
I'm not quite following what you mean here, are you trying to display the var from the JS file as an element on the HTML document?

So,
I've got a js file that acts as a slider and when the slider is on X the button for the link needs to be on X (when the slider is on Y the button needs to link to Y etc)

I've added the bit in the thread you linked me to and now need the var "link_arr" from another js file to be set as the var "id" in this html file
_IXYI0zFQmW_1ZCn_xqJ-g.png
 

Shaun

Web Developer, owner of Syncore LLC
Supreme
Feedback score
20
Posts
622
Reactions
408
Resources
0
I think it would be better to set the id variable to an array of ids and then have each link on each slide have a unique ID such as 'one' , 'two' , 'three', etc. and in the JS, just display a certain array for every certain ID. For example, unique link #1 has an id = "one" and then array #1 would be displayed there and so on and so forth. Then again, by no means am I a JS expert
 

Dann

Managing Director @ PebbleHost
Supreme
Feedback score
49
Posts
867
Reactions
762
Resources
0
I think it would be better to set the id variable to an array of ids and then have each link on each slide have a unique ID such as 'one' , 'two' , 'three', etc. and in the JS, just display a certain array for every certain ID. For example, unique link #1 has an id = "one" and then array #1 would be displayed there and so on and so forth. Then again, by no means am I a JS expert
When i do that, It just comes out with [object%20HTMLSpanElement]
 

Guru Websites

A Specialist in Gaming Website Development
Supreme
Feedback score
18
Posts
225
Reactions
93
Resources
0
Are you using jQuery?
 

Guru Websites

A Specialist in Gaming Website Development
Supreme
Feedback score
18
Posts
225
Reactions
93
Resources
0
Try this.
$("#price_val").attr('href', myURL);

Let me know how it goes.
 

Guru Websites

A Specialist in Gaming Website Development
Supreme
Feedback score
18
Posts
225
Reactions
93
Resources
0
Any errors in console?
 

Dann

Managing Director @ PebbleHost
Supreme
Feedback score
49
Posts
867
Reactions
762
Resources
0
Any errors in console?
Its web based, I'm wanting to have this slider change the href of the button depending on where the slider is, I've got the slider sorted and everything like that just having problems in getting the var into the html file
Currently this is what I'm using to display the var's in plain text and it works.

<aside class="smallbox2"> Monthly: <span id="price_val"></span>
 

Guru Websites

A Specialist in Gaming Website Development
Supreme
Feedback score
18
Posts
225
Reactions
93
Resources
0
I understand. If you right click the page then click inspect, you'll see a console. Is there any errors there?
 

Guru Websites

A Specialist in Gaming Website Development
Supreme
Feedback score
18
Posts
225
Reactions
93
Resources
0
I don't know man. I'd need to have a look myself
 
Status
This thread has been locked.
Top