简体   繁体   中英

How to dynamically add a link to a button?

This is tied to this question.

How can I dynamically add an HREF as a field is filled out?

I had success getting the link to work but it has been decided that the link would be better as a button. Here is what I have for the link.

The function I used

function buildPMLink(){
       let urlStart = "https://www.projectmanagement.com?query=";
       let urlEnd = "&showResults=False";
       let campRef = document.getElementByID("campid").value;
       let fullURL = urlStart + campRef + urlEnd;
       document.getElementById('pmURL').href = fullURL;

    }

The field that triggers the function

<div class="input-field col s3">
    <input placeholder="Enter Campaign ID" id="campid" type="text" class="validate" oninput="buildWFLink(); buildPMLink();" required >
    <label for="campaign_id">Campaign ID</label>
</div>

The link I added the dynamic HREF to.

<div >
     <a id="pmURL">Test</a>
 </div>

I tried creating a button and wrapping that in a form hoping to use the form action but failed. What am I missing?

You can do something very simple like this:

<a id="pmURL"><button>Test</button></a>

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