0

I have some javascript code that is being executed before pressing submit button ,even the html form is not displayed. What I want is to fill out a form and these data input will be used in the controller.After that what is returned from the controller will be used in the javascript function.

I do not know why it doesn't work.

this is my code

@model highchart.Models.model2
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

<html>

<body>
  <form Action="Index" method="post">

    <span> taux de change:"   </span>

    <input name="taux" value="EUR/USD" />
    <input type="text" id="txtId">

    <table>
      <tr>
        <th>Date_début</th>
        <th>Date_fin</th>
      </tr>
      <tr>
        <td>
          <input type="Date" name="date_début" id="date_début" value="@(Request.Form[" date_début "])"/>
        </td>


        <td>

          <input type="Date" name="date_fin" id="date_fin" value="@(Request.Form[" date_fin "])"/>
        </td>

    </table>
    <input type="submit" value="AFFICHE" name="affiche" onclick="storeInSession()" />
  </form>
  <script type="text/javascript">
    function storeInSession() {
      window.sessionStorage['submit'] = document.getElementById('txtId').value;
    }


    function checkSubmitStatus() {
      if (window.sessionStorage['submit']) {

        ('#container').highcharts({
          title: {
            text: 'Monthly Average Temperature',
            x: -20 //center
          },
          subtitle: {
            text: 'Source: WorldClimate.com',
            x: -20
          },
          xAxis: {
            categories: (function checkSubmitStatus() {
              var data = [];

              @foreach(var x in Model.temps) {
                @: data.push(@x);
              }
              alert(data[0]);

              return data;


            }())


          },
          yAxis: {
            title: {
              text: 'Temperature (°C)'
            },
            plotLines: [{
              value: 0,
              width: 1,
              color: '#808080'
            }]
          },
          tooltip: {
            valueSuffix: '°C'
          },
          legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
          },
          series: [{
            name: 'Tokyo',
            data: (function checkSubmitStatus() {
              var data = [];

              @foreach(var x in Model.high) {
                @: data.push(@x);
              }
              alert(data[0]);

              return data;


            }())
          }]

        });


        window.sessionStorage['submit'] = '';
      }
    }

  </script>

</body>

</html>
6
  • you should probably format that code a little better. and why do you have script tags outside of the <html> tag? and what is that @models tag?
    – karina
    Apr 18, 2016 at 15:55
  • I have written the javacript inside the <html> tag! and the @models is a class ! I have tested the javascript function and it works correctly but the problem with the synchronisation.
    – pika
    Apr 18, 2016 at 16:04
  • 2
    Can you also tag this with the appropriate templating engine you are using if any? You may get more relevant people to look at this. To me this looks like one of those cases of mixing server-side and client-side code.
    – apokryfos
    Apr 18, 2016 at 16:13
  • Yeah, what @apokryfos said. I don't recognize the templating engine, but i am getting a bad code smell from you reusing the name checkSubmitStatus for your functions over and over again...
    – karina
    Apr 18, 2016 at 16:20
  • I am using asp.net mvc
    – pika
    Apr 18, 2016 at 18:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.