I have a variable called location
that users put a URL in. I was able to take that URL and convert it to an HTML link. I found out though if the user puts a link in with a space, where there should be a %20
, the HTML link breaks. Here is my code to try and fix any blank spaces but it doesn't seem to be working.
var medias = []
var type = FilePlanForm.Items[i].Fields["Media Location"].Value;
var location = FilePlanForm.Items[i]["Media Location"].Value;
if ((location != null) && (location.indexOf(/\s/g) > -1)) {
location.replace(/\s/g, "%20");
}
if ((type == null) && (location != null) && (location.length >0)) { medias.push("Medias Type not selected" + " - " + location); }
else if((location != null) && (location.length > 0)) {medias.push(type + " - " + location); }
var type = FilePlanForm.Items[i].Fields["Media Location 2"].Value;
var location = FilePlanForm.Items[i]["Media Location 2"].Value;
if ((location != null) && (location.indexOf(/\s/g) > -1)) {
location.replace(/\s/g, "%20");
}
if ((type == null) && (location != null) && (location.length >0)) { medias.push("Medias Type not selected" + " - " + location); }
else if((location != null) && (location.length > 0)) {medias.push(type + " - " + location); }
I have also tried using the encodeURI function, but if the user enters the URL correctly and without any spaces, it breaks the URL.
Thanks