Answer the question
In order to leave comments, you need to log in
How to pass js variable to php?
php file. Using the function, I display a visual, including links, by clicking on which, the say (this, 1) function is executed. It passes the value of the value tag to the js text_value variable, and fires an alert on that variable.
However, I need to transfer this js variable to a php variable. (text_value - this value is needed to create a link to the file, from where I load json data and feed them to armcharts - creating charts).
At the end of the code there is this line
$p1= "<script>document.writeln(text_value);</script>";
<?
$head->addFile('/components/excel_loader/admin/tmp/ui.css');
$stat_data = $db->query('SELECT id, title, views, statistic, total_views FROM com_page where statistic =1');
$stat_data = $stat_data->fetchAll();
function a_com()
{
global $stat_data, $ourData;
echo '
<div id="main">
<h1>Статистика просмотра страниц</h1>
</div>';
$change="{MAIN_PAGE_CITY}";
foreach($stat_data as &$iter) {
$title = str_replace($change,'',$iter['title']);
echo '<br><span><a href="https://xn--63-vlch8au.xn--p1ai/admin/com/statistic/?id='.$iter['id'].'"
name="" value="'.$iter['id'].'" onclick="say(this, 1)">' . $title . '. </a> </span>: '.$iter['total_views'].' просмотр';
echo $ourData = file_get_contents('stat/'.$iter['id'].'.json');
}
}
?>
<script>
function say(element, id) {
var text_value = $(element).attr('value');
alert (text_value);
return text_value;
}
</script>
<? $p1= "<script>document.writeln(text_value);</script>";
echo $p1;
?>
Answer the question
In order to leave comments, you need to log in
Through the form I do not want - I need all the code to be executed in one file.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question