Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何向iPad iOS Safari和/或Chrome提交HTML隐藏表单字段?_Javascript_Html_Template Toolkit - Fatal编程技术网

Javascript 如何向iPad iOS Safari和/或Chrome提交HTML隐藏表单字段?

Javascript 如何向iPad iOS Safari和/或Chrome提交HTML隐藏表单字段?,javascript,html,template-toolkit,Javascript,Html,Template Toolkit,我有一个简单的表单应用程序,可以与完整的操作系统/浏览器配合使用,但当我使用iPad提交表单数据时,字段数据都不会显示在结果页面上。所有其他数据都正确加载。我正在使用模板工具包用表单参数填充结果页面 HTML代码段: <input id='patientCity' name='patientCity' type='hidden'> <input id='patientState' name='patientState' type='hidden'> <label f

我有一个简单的表单应用程序,可以与完整的操作系统/浏览器配合使用,但当我使用iPad提交表单数据时,
字段数据都不会显示在结果页面上。所有其他数据都正确加载。我正在使用模板工具包用表单参数填充结果页面

HTML代码段:

<input id='patientCity' name='patientCity' type='hidden'>
<input id='patientState' name='patientState' type='hidden'>
<label for='zip'>Zip Code</label>
<input name='patientZip' id='patientZip' placeholder='Zip Code' type='text' class='mediumInput' required>
<span class="item">Address: </span><span class="info"> [% params.patientStreet %]; [% params.patientCity %], [% params.patientState %] [% params.patientZip %] </span>
TT HTML代码段:

<input id='patientCity' name='patientCity' type='hidden'>
<input id='patientState' name='patientState' type='hidden'>
<label for='zip'>Zip Code</label>
<input name='patientZip' id='patientZip' placeholder='Zip Code' type='text' class='mediumInput' required>
<span class="item">Address: </span><span class="info"> [% params.patientStreet %]; [% params.patientCity %], [% params.patientState %] [% params.patientZip %] </span>
地址:[%params.patientStreet%];[%params.patientCity%],[%params.patientState%][%params.patientZip%]

谢谢

我认为您的第一个错误是没有使用JS框架,因此事件附加可能不会像@klugerama所说的那样发生。我提供了一个JSFIDLE,它是基于我认为您在这里要做的事情

下面是那把小提琴的JS:

// using jQuery as you really should be using a JS framework, but if not you could attach events using pure JS, but then you need to manage attaching events for all browsers.

var patientZipContext = $("#patientZip");
var patientCityContext = $("#patientCity");
var patientStateContext = $("#patientState");
var showHiddenContext = $("#showHidden");


console.log(patientZipContext)
console.log(patientCityContext)
console.log(patientStateContext)

function populateCityState(zipCode) {
    // Whatever your code does. Returning dummy code for now.
    return ["someCity", "someState"];
}

showHiddenContext.on("click", function() {
    $("input[type='hidden']").each(function() {
        this.setAttribute("type", "text");
    })
});

patientZipContext.on("change", function() {
    var cityState;

    console.log("onchange fired");
    cityState = populateCityState(this.value);

    // code to handle empty or incomplete array goes here

    patientCityContext.val(cityState[0]);
    patientStateContext.val(cityState[1]);
});

你在桌面Safari中试过这个吗?事实上你正在使用TT是不相关的。设备从未看到该代码。也就是说,我没听说过iPad有隐藏字段的问题。我在桌面Safari上试过,但它不起作用。它与Chrome完全兼容,但与iOS Chrome应用程序不兼容;可能是
document.getElementById($actualZip).onchange
事件没有正确触发。有很多帖子都是关于这件事的。试着在里面放些东西(可能不警惕?)来检查一下。非常感谢你的回答!我不得不说,我写代码是为了编码的乐趣和挑战。JS框架很棒,但我觉得它们对我来说太过有趣了。也就是说,我通常在所有项目中少量使用jQuery。