0

I have the code that follows. The goal is to check if the Name variable starts with TBD. If it does the whole variable will be populated to another location. However, if and only if it starts with "TBD - Hot" will it be treated differently.

<script type = "text/javascript">

if ("%%%Name%%%"=="TBD")  {document.write('<iframe width="100%" height="550" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" src=""></iframe>');
}
else if ("%%%Name%%%"=="TBD - HOT")  {document.write('<iframe width="100%" height="550" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" src=""></iframe>');
}
else {document.write('<iframe width="100%" height="550" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" src=""></iframe>');
}

</script>
0

3 Answers 3

1

String.prototype.indexOf is what you are seeking

if (str.indexOf('TBD - HOT') === 0) {

} else if (str.indexOf('TBD') === 0) {

} else {

}
0

An alternative would be String.prototype.substring which is faster in some browsers:

if (str.substring(0, 9) === "TBD - HOT") {

}
else if (str.substring(0, 3) === "TBD") {

}
else {

}
0

You also can use RegExp in here

if ((/^(TBD - HOT).*/).test(str) === 0) {

} else if ((/^(TBD).*/).test(str) === 0) {

} else {

}

Not the answer you're looking for? Browse other questions tagged or ask your own question.