-2

I am building a tool the builds URLs. One field in this tool is where the user enters the campaign ID. This ID corresponds to a campaign ID in our project management platform. What I am attempting to do is as the campaign ID is entered in the text field the HREF is updated.

For example.

Simplified project management URL:

www.projectmanagement.com?query=campaignID&showResults=False;

Campaign ID: 1234567

HREF for the link should be:

 www.projectmanagement.com?query=1234567

I've tried building a function and triggering that function with oninput(note that the field already calls one function)

The function looks something like this

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 HTML looks like this

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 want to add the dynamic HREF too.

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

Just doesn't seem to work. Any ideas?

Brad
  • 159,648
  • 54
  • 349
  • 530
  • just make another higher order function that triggers both buildPMLink and buildWFLink, and use it instead – Krzysztof Krzeszewski Jun 10 '20 at 15:38
  • Does this answer your question? [How to change href attribute using JavaScript after opening the link in a new window?](https://stackoverflow.com/questions/15385207/how-to-change-href-attribute-using-javascript-after-opening-the-link-in-a-new-wi) – Gerard Jun 10 '20 at 15:44
  • `document.getElementById('pmURL').setAttribute('href', fullURL)` should work – Gerard Jun 10 '20 at 15:47

1 Answers1

0

It is a typo. document.getElementByID should be document.getElementById. You can easily spot it from the console.

37:27 Uncaught TypeError: document.getElementByID is not a function

Working fiddle:

https://jsfiddle.net/61wcahxL/3/

Tu.Ma.
  • 1,325
  • 10
  • 27