Send without giving Refresh and using onchange [closed]

1

I want to send without refreshing my page and using on change I am using the code below

Form:

<form action="" id="ajax_form" method="post" >
      <input type="text" name="resultado1" size="5" onChange="envia()">
</form>

Submission script

jQuery('#ajax_form')(function envia() {
    var dados = jQuery(this).serialize();
    jQuery.ajax({
        type: "POST",
        url: "resultados.php",
        data: dados,
        success: function(data) {
            alert(data);
        }
    });
    return false;
});
    
asked by anonymous 25.04.2016 / 06:38

1 answer

0

If you want to retrieve the input value, place an identifier on it. For example id="meu_input"

<input id="meu_input" type="text" name="resultado1" size="5" onChange="envia()">
    </form> 

Then, find the value of this input by the ID. So:

$.post("resultados.php",{resultado1: $("#meu_input").val()},function(){});

I just modified your code, I'm not sure if I use the event in this way, wrath funcior, since you're using JQuery, I recommend you get the change event, in this way (After setting the ID):

$("#meu_input").change(function(event){
    alert($(event.target).val());
});

Applying your code:

$("#meu_input").change(function(event){
    $.post("resultados.php",{resultado1: $(event.target).val()},function(){});
});
    
25.04.2016 / 06:44