Assigning variable in document.getElementById(#div).innerHTML by radio button












0















folks!



I have a form with 40 radio type inputs and I have 40 cells with the same value.



I take capturing the radio send and assign to document.getElementById (VARIAVEL) .innerHTML.



I can retrieve the value of the radio and display on the screen with 'echo', but I can not send the information to the corresponding cell in the table with the document.getElementById (#id) .innerHTML, which leads me to believe that I do not I'm sure how to set it up.



I would want the radio value to set in which cell the content will be displayed.



I have looked at several books and I have not found it and on the internet what I have just confused.



I retrieve the value of the radio and I can see it on the screen with 'echo' but I can not send the information to the corresponding cell with the document.getElementById (#id) .innerHTML. I already looked at several books and I did not find it and on the internet what I found just confused me.



The code to better understand my question would look something like this:



HTML



<html>
<body>
<table>
<tr>
<td><div id="value1"></div></td>
<td><div id="value2"></div></td>
<td><div id="value3"></div></td>
</tr>
</table>

<form action="script.php" id="test" method="GET">
<input type="text" name="test">
<input value="value1" name="idradio" type="radio" />valor1</td>
<input value="value2" name="idradio" type="radio" />valor2</td>
<input value="value3" name="idradio" type="radio" />valor3</td>
</body>
</html>


JAVASCRIPT



<script>
var content = "Any content";
var var_id_radio = '<?php echo $_GET['idradio'];?>';
document.getElementById(var_id_radio).innerHTML=content;
</script>


p.s.: I know that the variable "var_id_radio" is not placed in that way, this is precisely the reason for the question, I do not know how to setting the variable (), I think I can do, but I have not found it yet. Can someone help me? Thank you.










share|improve this question























  • Try var var_id_radio = "<?php echo $_GET['idradio'];?>"; alert( var_id_radio );

    – Zakaria Acharki
    Nov 27 '18 at 11:17











  • Thank you but unfortunately the document.getElementById().InnerHTML does not recognize the variable.

    – Henrique Costa
    Nov 27 '18 at 14:42
















0















folks!



I have a form with 40 radio type inputs and I have 40 cells with the same value.



I take capturing the radio send and assign to document.getElementById (VARIAVEL) .innerHTML.



I can retrieve the value of the radio and display on the screen with 'echo', but I can not send the information to the corresponding cell in the table with the document.getElementById (#id) .innerHTML, which leads me to believe that I do not I'm sure how to set it up.



I would want the radio value to set in which cell the content will be displayed.



I have looked at several books and I have not found it and on the internet what I have just confused.



I retrieve the value of the radio and I can see it on the screen with 'echo' but I can not send the information to the corresponding cell with the document.getElementById (#id) .innerHTML. I already looked at several books and I did not find it and on the internet what I found just confused me.



The code to better understand my question would look something like this:



HTML



<html>
<body>
<table>
<tr>
<td><div id="value1"></div></td>
<td><div id="value2"></div></td>
<td><div id="value3"></div></td>
</tr>
</table>

<form action="script.php" id="test" method="GET">
<input type="text" name="test">
<input value="value1" name="idradio" type="radio" />valor1</td>
<input value="value2" name="idradio" type="radio" />valor2</td>
<input value="value3" name="idradio" type="radio" />valor3</td>
</body>
</html>


JAVASCRIPT



<script>
var content = "Any content";
var var_id_radio = '<?php echo $_GET['idradio'];?>';
document.getElementById(var_id_radio).innerHTML=content;
</script>


p.s.: I know that the variable "var_id_radio" is not placed in that way, this is precisely the reason for the question, I do not know how to setting the variable (), I think I can do, but I have not found it yet. Can someone help me? Thank you.










share|improve this question























  • Try var var_id_radio = "<?php echo $_GET['idradio'];?>"; alert( var_id_radio );

    – Zakaria Acharki
    Nov 27 '18 at 11:17











  • Thank you but unfortunately the document.getElementById().InnerHTML does not recognize the variable.

    – Henrique Costa
    Nov 27 '18 at 14:42














0












0








0








folks!



I have a form with 40 radio type inputs and I have 40 cells with the same value.



I take capturing the radio send and assign to document.getElementById (VARIAVEL) .innerHTML.



I can retrieve the value of the radio and display on the screen with 'echo', but I can not send the information to the corresponding cell in the table with the document.getElementById (#id) .innerHTML, which leads me to believe that I do not I'm sure how to set it up.



I would want the radio value to set in which cell the content will be displayed.



I have looked at several books and I have not found it and on the internet what I have just confused.



I retrieve the value of the radio and I can see it on the screen with 'echo' but I can not send the information to the corresponding cell with the document.getElementById (#id) .innerHTML. I already looked at several books and I did not find it and on the internet what I found just confused me.



The code to better understand my question would look something like this:



HTML



<html>
<body>
<table>
<tr>
<td><div id="value1"></div></td>
<td><div id="value2"></div></td>
<td><div id="value3"></div></td>
</tr>
</table>

<form action="script.php" id="test" method="GET">
<input type="text" name="test">
<input value="value1" name="idradio" type="radio" />valor1</td>
<input value="value2" name="idradio" type="radio" />valor2</td>
<input value="value3" name="idradio" type="radio" />valor3</td>
</body>
</html>


JAVASCRIPT



<script>
var content = "Any content";
var var_id_radio = '<?php echo $_GET['idradio'];?>';
document.getElementById(var_id_radio).innerHTML=content;
</script>


p.s.: I know that the variable "var_id_radio" is not placed in that way, this is precisely the reason for the question, I do not know how to setting the variable (), I think I can do, but I have not found it yet. Can someone help me? Thank you.










share|improve this question














folks!



I have a form with 40 radio type inputs and I have 40 cells with the same value.



I take capturing the radio send and assign to document.getElementById (VARIAVEL) .innerHTML.



I can retrieve the value of the radio and display on the screen with 'echo', but I can not send the information to the corresponding cell in the table with the document.getElementById (#id) .innerHTML, which leads me to believe that I do not I'm sure how to set it up.



I would want the radio value to set in which cell the content will be displayed.



I have looked at several books and I have not found it and on the internet what I have just confused.



I retrieve the value of the radio and I can see it on the screen with 'echo' but I can not send the information to the corresponding cell with the document.getElementById (#id) .innerHTML. I already looked at several books and I did not find it and on the internet what I found just confused me.



The code to better understand my question would look something like this:



HTML



<html>
<body>
<table>
<tr>
<td><div id="value1"></div></td>
<td><div id="value2"></div></td>
<td><div id="value3"></div></td>
</tr>
</table>

<form action="script.php" id="test" method="GET">
<input type="text" name="test">
<input value="value1" name="idradio" type="radio" />valor1</td>
<input value="value2" name="idradio" type="radio" />valor2</td>
<input value="value3" name="idradio" type="radio" />valor3</td>
</body>
</html>


JAVASCRIPT



<script>
var content = "Any content";
var var_id_radio = '<?php echo $_GET['idradio'];?>';
document.getElementById(var_id_radio).innerHTML=content;
</script>


p.s.: I know that the variable "var_id_radio" is not placed in that way, this is precisely the reason for the question, I do not know how to setting the variable (), I think I can do, but I have not found it yet. Can someone help me? Thank you.







javascript php jquery ajax






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '18 at 10:57









Henrique CostaHenrique Costa

11




11













  • Try var var_id_radio = "<?php echo $_GET['idradio'];?>"; alert( var_id_radio );

    – Zakaria Acharki
    Nov 27 '18 at 11:17











  • Thank you but unfortunately the document.getElementById().InnerHTML does not recognize the variable.

    – Henrique Costa
    Nov 27 '18 at 14:42



















  • Try var var_id_radio = "<?php echo $_GET['idradio'];?>"; alert( var_id_radio );

    – Zakaria Acharki
    Nov 27 '18 at 11:17











  • Thank you but unfortunately the document.getElementById().InnerHTML does not recognize the variable.

    – Henrique Costa
    Nov 27 '18 at 14:42

















Try var var_id_radio = "<?php echo $_GET['idradio'];?>"; alert( var_id_radio );

– Zakaria Acharki
Nov 27 '18 at 11:17





Try var var_id_radio = "<?php echo $_GET['idradio'];?>"; alert( var_id_radio );

– Zakaria Acharki
Nov 27 '18 at 11:17













Thank you but unfortunately the document.getElementById().InnerHTML does not recognize the variable.

– Henrique Costa
Nov 27 '18 at 14:42





Thank you but unfortunately the document.getElementById().InnerHTML does not recognize the variable.

– Henrique Costa
Nov 27 '18 at 14:42












1 Answer
1






active

oldest

votes


















0














You cannot retrieve value from PHP code like that.
PHP runs on server, but Javascript runs on the client side.
You can pass PHP Variables to your JavaScript by generating it with PHP:



// script.php
<?php
$radioValue = $_GET['idradio'];
?>

// JAVASCRIPT
<script type="text/javascript">
var javaScriptVar = "<?php echo $radioValue; ?>";
</script>





share|improve this answer
























  • Thanks for the tip but the document.getElementById( var here ).InnerHTML does not recognize the variable. This would be perfect...

    – Henrique Costa
    Nov 27 '18 at 14:40











  • How about you do console.log(javaScriptVar) to check it. It should be equal to some radio id.

    – parndepu
    Nov 27 '18 at 17:53











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53498141%2fassigning-variable-in-document-getelementbyiddiv-innerhtml-by-radio-button%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You cannot retrieve value from PHP code like that.
PHP runs on server, but Javascript runs on the client side.
You can pass PHP Variables to your JavaScript by generating it with PHP:



// script.php
<?php
$radioValue = $_GET['idradio'];
?>

// JAVASCRIPT
<script type="text/javascript">
var javaScriptVar = "<?php echo $radioValue; ?>";
</script>





share|improve this answer
























  • Thanks for the tip but the document.getElementById( var here ).InnerHTML does not recognize the variable. This would be perfect...

    – Henrique Costa
    Nov 27 '18 at 14:40











  • How about you do console.log(javaScriptVar) to check it. It should be equal to some radio id.

    – parndepu
    Nov 27 '18 at 17:53
















0














You cannot retrieve value from PHP code like that.
PHP runs on server, but Javascript runs on the client side.
You can pass PHP Variables to your JavaScript by generating it with PHP:



// script.php
<?php
$radioValue = $_GET['idradio'];
?>

// JAVASCRIPT
<script type="text/javascript">
var javaScriptVar = "<?php echo $radioValue; ?>";
</script>





share|improve this answer
























  • Thanks for the tip but the document.getElementById( var here ).InnerHTML does not recognize the variable. This would be perfect...

    – Henrique Costa
    Nov 27 '18 at 14:40











  • How about you do console.log(javaScriptVar) to check it. It should be equal to some radio id.

    – parndepu
    Nov 27 '18 at 17:53














0












0








0







You cannot retrieve value from PHP code like that.
PHP runs on server, but Javascript runs on the client side.
You can pass PHP Variables to your JavaScript by generating it with PHP:



// script.php
<?php
$radioValue = $_GET['idradio'];
?>

// JAVASCRIPT
<script type="text/javascript">
var javaScriptVar = "<?php echo $radioValue; ?>";
</script>





share|improve this answer













You cannot retrieve value from PHP code like that.
PHP runs on server, but Javascript runs on the client side.
You can pass PHP Variables to your JavaScript by generating it with PHP:



// script.php
<?php
$radioValue = $_GET['idradio'];
?>

// JAVASCRIPT
<script type="text/javascript">
var javaScriptVar = "<?php echo $radioValue; ?>";
</script>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 11:46









parndepuparndepu

589311




589311













  • Thanks for the tip but the document.getElementById( var here ).InnerHTML does not recognize the variable. This would be perfect...

    – Henrique Costa
    Nov 27 '18 at 14:40











  • How about you do console.log(javaScriptVar) to check it. It should be equal to some radio id.

    – parndepu
    Nov 27 '18 at 17:53



















  • Thanks for the tip but the document.getElementById( var here ).InnerHTML does not recognize the variable. This would be perfect...

    – Henrique Costa
    Nov 27 '18 at 14:40











  • How about you do console.log(javaScriptVar) to check it. It should be equal to some radio id.

    – parndepu
    Nov 27 '18 at 17:53

















Thanks for the tip but the document.getElementById( var here ).InnerHTML does not recognize the variable. This would be perfect...

– Henrique Costa
Nov 27 '18 at 14:40





Thanks for the tip but the document.getElementById( var here ).InnerHTML does not recognize the variable. This would be perfect...

– Henrique Costa
Nov 27 '18 at 14:40













How about you do console.log(javaScriptVar) to check it. It should be equal to some radio id.

– parndepu
Nov 27 '18 at 17:53





How about you do console.log(javaScriptVar) to check it. It should be equal to some radio id.

– parndepu
Nov 27 '18 at 17:53




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53498141%2fassigning-variable-in-document-getelementbyiddiv-innerhtml-by-radio-button%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Lallio

Futebolista

Jornalista