In PHP I have a function, the problem is it will output an extra || at the end that I dont want.
<script type="text/javascript">
function hide_card_code() {
var payment_source=document.getElementById('payment_source');
if(
<?
forEach($result_cards as $key => $value) {
echo "payment_source.value=='$value' || \n";
}
?>
) {
//do stuff...
return true;
}
}
</script>
It will output the following HTML. Note the extra || at the end.
<script type="text/javascript">
function hide_card_code() {
var payment_source=document.getElementById('payment_source');
if(
payment_source.value=='23' ||
payment_source.value=='24' ||
payment_source.value=='25' ||
) {
//do stuff...
return true;
}
}
</script>
How do I stop that extra || ?
No need for a loop! Just use
json_encodeto make a JavaScript array out of the values: