简体   繁体   中英

how to get document property value in html script

Is there a way to get document property values into html script in text area.

for example: I have a drop down which have values like "google","yahoo","Facebook" and my html script may be like

< SpotfireControl id="a23e53a498af447294614ec708f50ede" /> A href="http://www.Document propety value.com/">.

So if you select google in drop down ,the above html script will change to

< SpotfireControl id="a23e53a498af447294614ec708f50ede" /> A href="http://www.google.com/">

I want to see this dropdown and link in one text area.

much appreciated

If your tag is as follows:

<a id="mylink" href="">

Then you can set the href like so:

document.getElementById("mylink").href = "https://google.com";

If your select has an id="myselect" , you can get the value like so:

document.getElementById("myselect").value

Now you can set your link:

var site = document.getElementById("myselect").value;
document.getElementById("mylink").href = "https://"+site+".com";

Now, you want this to happen when you change the drop-down (select) option, so you'll need to add an event listener for when it changes.

document.getElementById("myselect").addEventListener("change",
    function() {
        var site = document.getElementById("myselect").value;
        document.getElementById("mylink").href = "https://"+site+".com";
    }
}

Do note that your event listener can only be added after the selector and the link have loaded (so the code needs to be afterwards). If you've never used JavaScript before, you should note that you need <script type="text/javascript"> and </script> tags to enclose it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM