我有一个表格,我的客户必须在其中输入一些值。
我的表格是这样的:
<form action="javascript:send();" enctype="multipart/form-data" id="form_main"><input type="number" name="quantidade" id="qt">
我有一个像这样的名为“send()”的函数。
function send(arg1){
if(typeof(arg1) === "undefined"){
arg1 = 2
}
document.getElementById('qt').setAttribute('value',arg1);
下面我有一些 ajax 帖子等等...
我所有的表格都是通过邮寄方法发送到这个页面的:pacific_cbc_pr.php
我有一个像这样的变量。
$quantidade = $_POST['quantidade'];
问题是当某人在输入 quantidade 时输入 100 或 200。
变量 $quantidade 必须为“2”,因为我没有传递参数。但是,$quantidade 设置为客户输入的值。
有人可以帮助我,因为变量 $quantidade 必须是来自的值:
文档.getelementbyID....
编辑:函数发送整个。
function send(arg1){
if(typeof(arg1) === "undefined"){
arg1 = 2
}
document.getElementById('qt').value = arg1;
$("#warning_alerta").hide();
$("#input_vazio").hide();
$("#login_erro").hide();
var formData = new FormData($('#form_principal')[0]);
$("#loading").show();
setTimeout(function() {
$.ajax({
url: "/xxxx/xxxx/xxxx/pacific_cbc_pr.php",
type: "post",
data: formData,
cache: false,
async:true,
contentType: false,
processData: false,
success: function(result){
if(result == 1)//logado
{
//$("#hide").show();
$('#text_modal').html('que');
$('#modal-container-188641').modal('show');
}
else if (result == 200)
{
$("#login_erro").show();
}
else if (result == 300)
{
$("#login_sucesso").show();
setTimeout(function(){
window.location = "index.php";},3000);
}
$("#loading").hide();
}
})
},300);
};
谢谢。
最佳答案
你需要像下面那样做:-
function send(){
document.getElementById("qt").value = 2;
}
顺便说一句,你可以简单地将自定义数据传递到你的 ajax post 表单中,而不是做这么多。
像下面这样:-
function send(){
$('#qt').val(2);//this is what you have to do
$("#warning_alerta").hide();
$("#input_vazio").hide();
$("#login_erro").hide();
$("#loading").show();
setTimeout(function() {
$.ajax({
url: "/xxxx/xxxx/xxxx/pacific_cbc_pr.php",
type: "post",
data: $('#form_main').serializeArray(),
cache: false,
async:true,
contentType: false,
processData: false,
success: function(result){
if(result == 1)//logado
{
//$("#hide").show();
$('#text_modal').html('que');
$('#modal-container-188641').modal('show');
}else if (result == 200){
$("#login_erro").show();
}else if (result == 300){
$("#login_sucesso").show();
setTimeout(function(){
window.location = "index.php";},3000);
}
$("#loading").hide();
}
});
},300);
};
关于javascript - 从函数 Javascript 设置变量 PHP 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45122403/