使用PHP的$ _POST在JavaScript折线图上显示值

时间:2017-10-16 12:31:51

标签: javascript php jquery html

我正在尝试为学校目的做练习。我正在使用Morris JS来显示我的折线图并使用PHP来发布表中的值。这是表输入:

CLICK ME

单击“提交”按钮时,将显示输入的值和Morris JS提供的折线图。折线图当前显示静态值。我想要发生的是,从表中输入的值中获取值。

HERE WAS MY PREVIOUS QUESTION

HTML Code Snippet:

<tr>
  <td>
    <label>American Indian/Alaska Native</label>
  </td>
  <td>
    <input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57' class="form-control" name="AmericanIndian_EP" value="" placeholder="Enter Value Here" />
  </td>
</tr>

PHP Code Snippet:

<tr>
  <td>
    <label>American Indian/Alaska Native</label>
  </td>
  <td>
    <input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57' class="form-control" name="AmericanIndian_EP" value="<?php echo $_POST["AmericanIndian_EP"];  ?>" disabled="" />
  </td>
</tr>

Morris JavaScript代码段:

$(function() {
  Morris.Line({
    element: 'morris-line-chart',
    data:  [
      { year: '2015', a: 20, b: 5, c: 30,  d: 35,  e: 14 },
      { year: '2016', a: 25, b: 8, c: 42,  d: 30,  e: 9 },
      { year: '2017', a: 40, b: 10, c: 49,  d: 20,  e: 11 },
    ],
    xkey: 'year',
    ykeys: ['a', 'b', 'c', 'd', 'e'],
    labels: ['Equity Partners ', 'Non Equity ', 'Associate ', 'Counsel ', 'Other Lawyer']
  });

我原本以为我可以在变量上输入PHP代码,但它不起作用。例如:

$(function() {
  Morris.Line({
    element: 'morris-line-chart',
    data: <?php json_encode([
      ['year'=>'2015','a'=>$_POST["AmericanIndian_EP"]],
      ['year'=>'2016','a'=>$_POST["AmericanIndian_A"]],
      ['year'=>'2017','a'=>$_POST["AmericanIndian_C"]]
    ]); ?>,
    xkey: 'year',
    ykeys: ['a'],
    labels: ['Equity Partners ']
  });

请帮忙。谢谢!

0 个答案:

没有答案