There is a problem.
Suppose there is a variable var my = 33 .
There is a code:

 var aloha = { id: my, type: 'mytype', lvalue: my, }; 

It is necessary that in the browser instead of my displayed 33 .
I tried different ways and experimented, but nothing happens.

When I have a variable in php , I just insert <?=$my;?> And that's it.
But when the value in the variable js , I have such a problem, please help.

What result do I want to get:
In order for the body of the document to have id: 33 when viewing the code in the browser, it should be like in the image below, only instead of my its value:

enter image description here

It is necessary to get it like this when viewing the code:

enter image description here

At the request of the respondents - the original code:

 var google_tag_params = { dynx_itemid: idsGoogleTag, dynx_pagetype: 'conversion', dynx_totalvalue: totalGoogleTag, }; 

The idsGoogleTag and totalGoogleTag store the values ​​I need.

Closed due to the fact that off-topic by the participants Sergiks , aleksandr barakin , fori1ton , user194374, Streletz Jul 10 '16 at 15:15 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Sergiks, aleksandr barakin, fori1ton, Community Spirit, Streletz
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Your question does not show the essence of the problem. Where exactly do you want to display the variable? In the body of an HTML document? - tutankhamun
  • Yes. so that the body of the document was id: 33 - mydls1
  • show the code where you get my instead of output 33 - Grundy
  • js fails. when there is a variable in php, something like this var aloha = {id: <? = $ my;?>, type: 'mytype', lvalue: <? = $ my;?>,}; - mydls1
  • this is possible only if you generate the script yourself - Grundy

3 answers 3

This is not a problem, var aloha is an object so that my equals 33 you need to write:

 aloha.id = 33 
  • Yes, I understand, but I cannot change the properties of the object id type, etc. (I need to get it like this, only through js id: <? = $ my?> which is equivalent to id: 33. (( - mydls1
  • and the lvalue property can be changed, just if the object cannot be changed, then why is it even needed in this example - pnp2000
  • No you can not. In the original, this is a google object, after: I must pass the values. properties cannot be changed, as it will not pass validation on input - mydls1

 <script> my=33; document.write("\u003Cscript>var aloha = {\nid: "+my+",\ntype: 'mytype',\nlvalue: "+my+", };\n\u003C/script>"); </script> 

Then how to look in the browser, if the inspector, the code is replaced.

    C jQuery:

     $('куда вставить').html(aloha.id) 

    possible without jQuery:

     var myBlock = document.getElementById('куда вставить'); myBlock.innerHTML = aloha.id; 
    • I added an image. - mydls1
    • one
      The answer is offtopic. jQuery is not specified in the question text or in the labels. Indicate, at least, in your answer when such a construction works - tutankhamun
    • it is possible without jQuery, var myBlock = document.getElementById ('where to insert'); myBlock.innerHTML = aloha.id; - illia.zt
    • html is why ((( - Qwertiy
    • @tutankhamun is straight the morals police, he also indicated that with jquery, I don’t see a problem. Without jquery, only jquery is being written now :) - KeyGenQt