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>