I hope someone can help with what is probably a beginner js question.
I am implementing a sign up form from a third party, which specifies the return URL (which I can set), and the 3rd party system returns the status appended to the return url, for example www.website.com/pagename?error=email exists
The return URL document is a flat html page so I plan to handle these (rightly or wrongly) by using javascript to interrogate the query string and display messages as appropriate. I am a js novice (code is below) so I am certain there are better ways to write it.
My problem is that this works as desired when the code is uploaded through a content managed web page. However when a simple test html page is uploaded with the identical js code, the show and hide of content fails. What am I missing? Any help and constructive criticism welcome, thank you.
Here is the full javascript code for reference. There are corresponding div elements with IDs to show depending on the query string.
There is one line in the javascript that will be removed but is included currently to show the page URL is being captured correctly and that the interrogation of the URL is working as expected:
function myFunction() {
var url = window.location.href
var str = url;
//look for "noemail"
var patt = /noemail/g;
var result = patt.test(str);
//look for "name"
patt2 = /name/g;
result2 = patt2.test(str);
//look for "invalid"
patt3 = /invalid/g;
result3 = patt3.test(str);
//look for "exists"
patt4 = /exists/g;
result4 = patt4.test(str);
var url = window.location.href;
document.getElementById("demo").innerHTML = result + "<br>" + result2 + "<br>" + result3 + "<br>" + result4 + "<br>" + url;
if (result) {
$("#noemail").show();
} else {
$("#noemail").hide();
}
if (result2) {
$("#name").show();
} else {
$("#name").hide();
}
if (result3) {
$("#invalid").show();
} else {
$("#invalid").hide();
}
if (result4) {
$("#exists").show();
} else {
$("#exists").hide();
}
}