I have a form on a webpage I am building where a user inputs a URL. The user has the option to enter a URL with two variants either containing PLT or PDW.
Example, www.userurl.plt.com or www.userurl.pdw.com
Now from this input I want to use some javascript to create a URL string based on what the user entered but to include both the entered and non entered.
what I have so far is this.
$(window).on('load', function() {
$('#open').click(function() {
var regex1 = /\.(PLT)\./i;
var regex2 = /\.(PDW)\./i;
var fixedData1 = 'http://www.myurl/user/?var-ip1=',
fixedData2 = '&var-ip2=',
userEntry1 = $('#one').val(),
replaced = userEntry1.replace(regex1, '.plt.');
replaced = userEntry1.replace(regex2, '.pdw.');
var newWindow = window.open(fixedData1 + userEntry1 + fixedData2 + replaced);
newWindow.focus();
});
});
I am quite new so probably doing something wrong but this works okay so,
If I entered www.testurl.pdw.com
I would get an output of:
http://www.myurl/user/?var-ip1=www.testurl.pdw.com&var-ip2=www.testurl.plt.com
Which is good!, but if I entered www.testurl.plt.com I get
http://www.myurl/user/?var-ip1=www.testurl.plt.com&var-ip2=www.testurl.plt.com
which is of course bad. Im not looking for anyone to just do it for me but any pointers in the right direction would be great, this is part of a bigger project and this is slowing me down. Many thanks
replaced = userEntry1.replace(regex1, '.plt.');andreplaced = userEntry1.replace(regex2, '.pdw.');.