As a complete novice in the world of CSS websites, I find myself struggling to accomplish what seems like a simple task. I am working with an automatically generated CSS/JavaScript website where on the "individual" page, a person's name is listed within an h2 tag. My goal is to extract this name and add it to a variable in a script that will then create a hyperlink labeled "View All Media," which when clicked will search a database based on the person's name.
<html>
<script language="javascript" type="text/javascript">
var scrt_var = ' ';
openPage = function() {location.href = "http://my.website.net/all_media.asp?tags="+scrt_var;}
</script>
<a href="javascript:openPage()">View All Media </a>
</html>
The specific tag containing the person's name on the "individual" page is <h2 id='name'></h2>
. This name needs to be appended to the hyperlink as a search parameter for the database. Unfortunately, my searches only turned up scripts that modify tags or add hyperlinks, rather than extracting data. I'm hoping to automate the process by pulling the name from the page/source instead of manually entering it into the script.
`<div id='content'>`
`<h1>Individual Details</h1>`
`<h2 id='name'></h2>`
If I hard-code the name in the script (e.g., var scrt_var = "John Doe";), everything works as expected. But my aim is to dynamically retrieve the name from the page/source and populate the "var" line automatically. This should be a straightforward task, but my lack of knowledge is proving to be a hindrance. Any guidance or thoughts would be greatly appreciated! And please, go easy on me - Thank you! 😊