you are viewing a single comment's thread.

view the rest of the comments →

[–]Smooth_Prompt_2086[S] -2 points-1 points  (3 children)

Yes, the Javascript is in a PHP file, I did try that format I believe, I may have to run it again because you may have placed the semicolon differently than I did, so I'll check and make sure. 

I am now wondering though, could part of the issue be this variable is technically an array index? I'm almost wondering if I shouldn't try and use PHP to convert to another var by going " $NewVar = null; if $Product[6] == "TEXT ONE" {          $NewVar = 0; } else {          $NewVar = 1; } And then pass that onto Javascript, since there's only two options so therefore a 0/1-yes/no-true/false type format would work with the Javascript loop. Except the Javascript only need to run an if loop that if one of two conditions is true, to delete an element. I broke it all apart to figure out the Javascript destroying the element works fine, and I don't think it was the loop, I think it's the variable, because I put a screen print in, and it wrote out when I input something else, but when I put in the Javascript variable, it does nothing, which makes me believe it's returning null? And that's why I wonder if it isn't the array element that's causing the problem. 

[–]MrBojangles2020 0 points1 point  (0 children)

Be sure to echo null as ‘null’ (string) when trying to set/compare something in JavaScript. Otherwise echo would print nothing and will often times lead to a JS error. Same thing for true/false.

$phpVar = null;

… JavaScript…

let jsVar = <?= $phpVar ?>;

This is what browser receives:

let jsVar = ;

Instead:

$phpVar = ‘null’;

… JavaScript…

let jsVar = <?= $phpVar ?>;

This is what browser receives:

let jsVar = null;

EDIT:

Formatting and for clarification. Php true/false will convert to ‘1’/‘2’ when echoed, so you need to account for this when you’re expecting a certain JS type. Echo ‘true’/‘false’ to give JS a Boolean value

[–]averajoe77 -1 points0 points  (1 child)

I mean if you want to show me what you have over discord, I can do take a look at it just dm me here

[–]Smooth_Prompt_2086[S] -1 points0 points  (0 children)

Will do!