Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for How to insert a php array with innerHTML in javascript

Current License: CC BY-SA 4.0

Post Revisions

18 events
when toggle format what by license comment
Jul 10, 2019 at 0:40 review Close votes
Jul 14, 2019 at 0:00
Jul 10, 2019 at 0:37 vote accept Community Bot
Jul 10, 2019 at 0:36 answer added Cornel Raiu timeline score: 2
Jul 10, 2019 at 0:31 comment added user11486953 @cornel.raiu thank you
Jul 10, 2019 at 0:30 comment added Cornel Raiu I will add an answer
Jul 10, 2019 at 0:29 comment added user11486953 @cornel.raiu Yes. Already that error does not appear. What happens now is that, when printing the html that I indicate in innerHTML, the php part appears in the form of a comment.
Jul 10, 2019 at 0:27 comment added Cornel Raiu The error is not related to the content you are trying to add but to the fact that JS does not find this: document.getElementById('selectTeam') since the JS loads before the content in your case hence it is null. So, JS sees it like: (null).innerHTML='bla bla' which is not valid
Jul 10, 2019 at 0:24 comment added Cornel Raiu Possible duplicate of Cannot set property 'innerHTML' of null
Jul 10, 2019 at 0:23 comment added Cornel Raiu is it possible that when you do it using PHP the selectTeam element is not loaded BEFORE the JS part? Are you doing the JS part onLoad or smth? Check this example with the exact same error you get: stackoverflow.com/questions/18239430/…
Jul 10, 2019 at 0:23 comment added user11486953 @cornel.raiu Yes. Now the simplest examples work. For now the problem is in the php part inside the inner, I think I'm sure it's because of the double and single quotes
Jul 10, 2019 at 0:21 comment added Cornel Raiu does this work? document.getElementById('selectTeam').innerHTML = '<select class="form-control"><option value="123">Aha</option></select>';
Jul 10, 2019 at 0:20 comment added user11486953 @cornel.raiu The console throws the following error: login.js: 78 Uncaught TypeError: Can not set property 'innerHTML' of null. I have tried with a simpler example and it works. I think the problem is the combination of double and single quotes in the php part inside the innerHTML
Jul 10, 2019 at 0:18 comment added Cornel Raiu instead of the PHP code, try to hardcode an <option value="123">Aha</option> and see if that works
Jul 10, 2019 at 0:16 comment added Cornel Raiu what does "does not work" mean? it does not change the content? the content it changes to is not correct?
Jul 10, 2019 at 0:10 history edited user11486953 CC BY-SA 4.0
edited body
Jul 10, 2019 at 0:05 answer added JC Hernández timeline score: 0
S Jul 10, 2019 at 0:01 review Triage
Jul 10, 2019 at 0:05
S Jul 10, 2019 at 0:01 history asked user11486953 CC BY-SA 4.0
toggle format

AltStyle によって変換されたページ (->オリジナル) /