简体   繁体   English

如何在输入字段中提交Javascript值

[英]How to Submit a Javascript Value in an Input Field

Simply, how can I do this? 简单来说,我该怎么做?

<input type="hidden" value="some javascript value" />

I have a form whereby when a user clicks on Add More , more input fields are added via javascript. 我有一个表单,当用户单击“ 添加更多”时 ,会通过javascript 添加更多输入字段。

I'm also using javascript-declared values to track and limit the number of fields a user can add. 我还使用javascript声明的值来跟踪和限制用户可以添加的字段数。

I need a way for my php code to retrieve these javascript values . 我需要一种使我的php代码检索这些javascript值的方法

From the button you must be calling a javascript to add these fields dynamically. 从该按钮,您必须调用javascript以动态添加这些字段。 Simply append the code to that function to hand over these values to the field. 只需将代码附加到该函数即可将这些值移交给该字段。

<input id="myinputfield[]" type="hidden" value="" />
<script>
function addOneMore(){
      var newField = // code to add one more field
      newField.value = newValue; 
}
</script>

Will solve your purpose. 将解决您的目的。

the question is a bit vague, but i will give it a go 这个问题有点含糊,但我会试一试

try adding a name as an array and then you can use get or post 尝试将名称添加为数组,然后可以使用get或post

<input name="myjavascriptinputs[]" type="hidden" value="some javascript value" />

in your php you will be able to use 在您的PHP中,您将能够使用

foreach($_GET['myjavascriptinputs'] as $ajavascriptinput)

Use append 使用append

$('#hidden').val('my Text');

input field should be 输入字段应为

<input type="hidden" id="hidden"/>

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

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