onchange does not send the value

0

I have a problem with AJAX, I have a field in HTML:

<input type="hidden" id="numreporte" name="numeroreporte" value="30" >

And I have the following function:

function valnumreport(){

 $.ajax({
        type: 'POST',
        url: 'ruta.php',
        data:'numeroreporte='+ document.getElementById('numreporte').value,
        success:function(response){

   alert (numeroreporte);


  }
  });
}

And I call the function with a onchange :

onchange ='valnumreport()'

What I want is to send the value of hidden to another page with an event onchange but it does not send it, I'm just working with AJAX so I do not have much knowledge.

    
asked by natalia nar 22.06.2018 в 17:57
source

2 answers

0

Well to be able to answer you I will assume the following:

  • That you have a selector with n options to deploy.
  • That you have a hidden input field from which you expect to take the value to send to your page 'ruta.php' once you change the selection of the select
  • The attached link simulates the sending of the hidden field value to an external server, as a response from this external server you receive the same value that you sent, that is, the .value of the hidden field.

    Example of sending hidden value to external server

    I think this solves part of your question; If not, let me know.

        
    answered by 22.06.2018 в 20:52
    -1
    <input type='text' class='form-control' id='numreporte' name="numeroreporte"  maxlength='300'   required='required' autofocus>
    
    
    function valnumreport(){
    
    $.ajax({
        type: 'POST',
        url: 'ruta.php',
        data{
        'numeroreporte': $('#numreporte').val(),
        }
       success:function(response){
       alert (numeroreporte);
      }
      });
    }
    
        
    answered by 22.06.2018 в 18:14