简体   繁体   English

Chrome 没有获取表单变量

[英]Chrome not picking up form variables

I have a form that feeds variables into a piece of javascript for building a graph.我有一个表单可以将变量输入到一段用于构建图形的 javascript 中。 When running the page in chrome the submit button just reloads the page and the variable data from the form isn't gathered and fed into the javacript.在 chrome 中运行页面时,提交按钮只会重新加载页面,并且不会收集表单中的变量数据并将其输入 javacript。 Below is the snippet of code for the form and part of the javascript that picks up the variables and uses them in the URL.下面是表单的代码片段和 javascript 的一部分,它提取变量并在 URL 中使用它们。

This works perfectly in Firefox without a single error in sight.这在 Firefox 中完美运行,没有任何错误。 Chrome just refuses to pick up the input from the form. Chrome 只是拒绝从表单中获取输入。 Unfortunately the console hasn't picked up any errors either.不幸的是,控制台也没有发现任何错误。 I've tried using POST, but this doesn't resolve the issue, GET works anyhow when I run the PHP page with the variables included without issue.我试过使用 POST,但这并不能解决问题,当我运行包含变量的 PHP 页面时,GET 无论如何都可以正常工作。 I've done all I can to make the form as technically right as I can.我已尽我所能使表格在技术上尽可能正确。 I'm out of ideas.我没有想法了。 Changing the submit button doesn't resolve the issue either.更改提交按钮也不能解决问题。

<form name="forminput" id="forminput">
<label for="accountname">Account Name :</label>
<input type="text" id="accountname" name="accountname">
<br>
<label for="startpopupDatepicker">Start Date : </label>
<input type="text" id="startpopupDatepicker" name="startpopupDatepicker">
<label for="endpopupDatepicker">End Date : </label>
<input type="text" id="endpopupDatepicker" name="endpopupDatepicker">
<br>
Node : <select id="nodename" name="nodename">
    <option value="EU">EU</option>
    <option value="US">US</option>
    <option value="APAC">APAC</option> </select>
<input type="button" value="Submit" name="Submit" onclick="history.go()">
</form>

<script>
//Input Start

var account = document.getElementById("accountname").value;
var node = document.getElementById('nodename').value;
var calstartdate = document.getElementById('startpopupDatepicker').value;
var calenddate = document.getElementById('endpopupDatepicker').value;

//Input End
//Chart Beginning

var chart = c3.generate({
bindto: '#chart',
data: {
    x : 'date',
    url: 'sqlcallcounts2.php?account='+account+'&node='+node+'&startdate='+calstartdate+'&enddate='+calenddate,
},

I resolved this by making the whole of the Javascript that's in the page a function.我通过使页面中的整个 Javascript 成为一个函数来解决这个问题。 I then used the onClick of the Submit button to active the function.然后我使用提交按钮的 onClick 来激活该功能。 It now works perfectly.它现在可以完美运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM