JS creates a space while constructing URL

  • Goal: Im trying to structure a URL that have 2 different variables, like: 332016977200110000000001994277
    332016977200110000000001995085, my part of URL shall look like:
    \part of URL ommited\trackcode=332016977200110000000001994277%0D%0A332016977200110000000001995085

  • Steps: I used a JS that takes those numbers from textInput value:
    let trackingNumbers = textInput3.value.trim();
    let formattedTrackingNumbers = trackingNumbers.split(/\r?\n/).join('%0D%0A');
    Than construct URL:
    let trackingUrl = \\part of URL ommited\\trackcode=${formattedTrackingNumbers};

  • Details: in any case, the URL returned looks like:
    \part of URL ommited\trackcode=332016977200110000000001994277 332016977200110000000001995085
    The major needed element is missing %0D%0A

  • Screenshots:

  • App json export: (here's how to get a json export)

@oskar you can try this code

let trackingNumbers = textInput3.value.trim();

let formattedTrackingNumbers = trackingNumbers.split(/\r?\n/).join('%0D%0A');

formattedTrackingNumbers = encodeURIComponent(formattedTrackingNumbers);

let trackingUrl = `\\part_of_URL_omitted\\trackcode=${formattedTrackingNumbers}`;

1 Like

Thank you for your prompt response,
Tried those, the outcome is %20 instead %0D%0A

Found the Solution :slight_smile:
let trackingNumbers = textInput3.value.trim();

// Split the tracking numbers by spaces
let lines = trackingNumbers.split(' ');

// Encode each line separately and join with '%0D%0A'
let encodedLines = lines.map(line => encodeURIComponent(line)).join('%0D%0A');

2 Likes