1

i have a form where my customers must input some value at inputs.

my form is like this :

<form action="javascript:send();" enctype="multipart/form-data" id="form_main"><input type="number" name="quantidade" id="qt">

and i have a function called "send()" like this.

function send(arg1){


    if(typeof(arg1) === "undefined"){
        arg1 = 2
    }



    document.getElementById('qt').setAttribute('value',arg1);

below i have some ajax post and etc...

all my form is send by method post to this page : pacific_cbc_pr.php

where i have a variable like this.

$quantidade = $_POST['quantidade'];

the problem is that when someone for example input 100 or 200 at input quantidade .

the variable $quantidade must be "2" because i'm not passing parameter. but , the $quantidade is set with the value that the customer input.

someone could help me , because the variable $quantidade must be the value from :

document.getelementbyID....

EDIT : function send whole.

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);
};

Thanks.

1 Answer 1

2

You need to do it like below:-

function send(){
    document.getElementById("qt").value = 2;
}

BTW instead of doing this much you can simply pass custom data into your ajax post form.

do like below:-

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);
};
Sign up to request clarification or add additional context in comments.

3 Comments

how for example ? using ajax post form
show your ajax code through wich you are sending data of form. I will check and let you know
@Kamikaz0r i hhad changed code a bit righr now. so check the latest edit and use it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.