• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

modify href link with document.getElementById

frankpc

Member
Hello,

I need to dynamically modify a link based on a camera selection change. I am using this to detect the change:

document.getElementById('cam').innerHTML = camnum; //'camnum' ranges from 1 to 15.

I need for the result to append after "cam=" below:

<a href="http://fpc.cam.com/cam.html?rot=90&cam= [...<b id='cam'></b>.....]">click here</a>

Or perhaps:

document.write("<a href=\"http://fpc.cam.com/cam.html?rot=90&cam= [... + <b id='cam'></b> ...]\" ">click here</a>");

I found some other advice on this forum that came close, but it wasn't quite what I needed. Perhaps "document.getElementById" isn't applicable.

Would someone give me a hand here?
Thank you,
Frank
 
Well, first, the forum messed up your lines. Try unchecking the "Automatically parse links in text" checkbox. Code tags help too.

Now, despite not being able to see all your code, I'm pretty sure getElementById will get you where you need to be, or close enough that you can either look at .parentNode or .getElementsByTagName from there. Perhaps you want to modify the href property, rather than the innerHTML?
 
Assuming you already have a link on the page, it's as simple as:

Code:
document.getElementById("cam").href="New URL";
 
Thank you folks.

I unchecked the Auto parse lines box. However, the lines look proper from my browser. Can't say I understand why.

It works! Thank you for the simple cure to my problem. I searched and worked on this for two days.

Great Forum!

Thanks again!

Frank
 
Back
Top