Client-side JavaScript code behaves differently when loaded from different servers!

Hi there!
I don’t know what is happening, but here’s what I’m facing:

  • I had developed a site using the usual techs: PHP, SQLite and JavaScript.
  • On my machine everything works just fine, whether I’m using Linux or Windows, FireFox or Chrome, and on more than one machine as well.
  • But when I upload my files on the remote server, some JavaScript code doesn’t get executed!! But the code should have nothing to do with the server; it’s executed client-side!!!

I’m at a loss where else to look!!

I would appreciate any suggestion! A million thanks in advance!

Hosam Adeeb Nashed

Do you have a link to the live website where it doesn’t run so we can have a look?

I could do that, of course, only the live site is in Arabic, for starters.

Besides, it’s an evaluation system where contestants would be added to the system, and then judges would evaluate them. While doing that, certain fields are dealt with as if they have defaults; this works just fine if I’m using my local server. When using the live server, instead, those aforementioned fields fail to behave as having their default values, and one would need to enter those manually.

Hence, providing you with the link would no good, I’m afraid.

So, for example, the code between double asterisks is the problem:

theCell = eval("Hymn" + hymnNum + "Solo"); theSolo = verifyCell(theCell, 15); **if(theSolo == 0.01) theSolo = 15.0 * 0.75;**

Can I ask how you know that? Are there error’s being logged to the browser’s console?

Can I ask what is hymnNum? Why are you having to use eval?

What does a **if(… mean in JavaScript?

I think he was just highlighting that code e.g. **my code here**

1 Like

This happens within a loop:

  1. With hymnNum equalling 1, we’re dealing with the Hymn1Solo field.
  2. Then see if the content of that cell is not beyond 15. But if that cell is empty put a temporary value.
  3. If the cell is indeed empty (i.e. contains the temporary value), assume a default value of 11.25.

It’s that third step that doesn’t get executed on the live server, but runs just fine on my local server (the one I use for development).

I also don’t understand the eval. How can this return an input field?

eval takes its input expression and returns a concatenated name as if one has used it like that from the start.

So you have somewhere code where you put all your input fields in variables like

var hymn1solo = document.getElementById(„hymn1solo“);
var hymn2solo = document.getElementById(„hynm2solo“);

And so on for each input field?

1 Like

I asked about eval, because it is advised not to use it. Usually there are safer and more performant alternatives.

MDN - Never use eval

I could be wrong, but I wondered whether eval is the cause of the issue you are having. Is it’s use being blocked due to security risks?


I would be really surprised if eval were blocked! Because, if it were true, no part of the code would have been executed at all!! As it stands, every other part of the code runs just fine. Except, of course, that part I mentioned above that, somehow, gets skipped.

Let me update you with my latest findings.

From home, I logged into the live server, and tried to test things. All worked absolutely fine!!!

So, what I’m facing now is this:

  • From home, everything works just fine, on all browsers, on Linux and on Windows.
  • On the field, that piece of code refuses to run, again on all browsers, on Linux or on Windows.

This is just maddening!!! Insane!!

Mind you, all my browsers all kept up to date all the time. As are the OS’s.

Thank you all for bearing with me. Again, any ideas are most welcome.

Are you sure you have the exact same version of php and database on both servers?

I’ve made sure both servers are exact copies.

Well, today, everything went rather smoothly. I hadn’t done any changes. So, no idea what went wrong for two days, and how it went away on the third day. I’m completely baffled…

Thank you all for your patience. :heart:

Maybe is was a cache issue?

1 Like

I’d be surprised if it was… You see, we were nine people on the judging panel, each working on his/her own laptop and browser, and it was the first day to use the programme after the two-year stop due to Covid-19.

Besides, the part of the code that was skipped was indeed there all the time.

Fankly, I am at a complete loss why that happened, why and how it ceased to be, and how I can guard against it happening again!!!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.