I've got a simple JavaScript statement that reads a string and fires off a URL based of what it contains but I'm not sure if I've used IndexOf correctly so I just wanted to check.
Here is my code snippet:
<script type="text/javascript">
var mc_u1 = "somevariable";
if (mc_u1.indexOf("1|Accept") > 0) {
document.writeln("<img src=\"https://www.someurl1.com\">");
}
if (mc_u1.indexOf("1|Refer") > 0) {
document.writeln("<img src=\"https://www.someurl2.com\">");
}
if (mc_u1.indexOf("2|Accept") > 0) {
document.writeln("<img src=\"https://www.someurl3.com\">");
}
if (mc_u1.indexOf("2|Refer") > 0) {
document.writeln("<img src=\"www.someurl4.com\">");
}
</script>
As you can see from the code above, what I'm trying to do is based on the contents of the variable mc_u1 fire off a URL (which are different though I've just masked them for obvious reasons).
My question is, if the mc_u1 variable begins with say 1|Accept should I be using > -1 in the Javascript Statement or > 0?
Hope this is making sense!