提交带有自定义变量的表单的更好方法(提示)


Better way to submit a form with custom variable (prompt)?

我想从prompt()函数提交一个自定义变量的表单。

提交表单使用代码

document.formname.submit();

但是这只会提交表单,我想要的是:

var iInvoiceID = prompt("Please enter the invoice ID");
document.formname.submit(); // But it should send iInvoiceID within $_POST aswell

一种方法是:在提示之后,将输入type = 'hidden'设置为iInvoiceID的值,然后提交表单。但是有没有更好/更干净的方法来做这件事呢?

不,按照你的建议,

在提示符后,将输入类型= 'hidden'设置为iInvoiceID的值,然后提交表单。但是有没有更好/更干净的方法来做这件事呢?

是做你需要的最好的和最干净的。

编辑:


至于你的编辑,我认为document.formname.submitbutton1.click();应该做这项工作。

根据您的编辑,您似乎可以这样做:

$('#myform').submit(function() {
    $('#my_hidden_input').val(prompt('Please enter the invoice ID'));
});