3

This is my script that after changing input value should send it to php file with Ajax.But it's sending the actual value from input field which is set via php.How can i set the new value to be given?

var idg;
var newg;

$('input.readonly').live("click",
    function() {
    $(this).attr('readonly', false);
    idgs=$(this).attr('id');
    newg=$(this).attr('value');

    $(this).change(function(){
        $.ajax({
          type:'POST',
          url: 'new.php',
          data: "idgs="+ idgs +"&newg="+ newg,
          success: function(data) { $('.right').html(data); }
        });
    })
}); 
1
  • can you point out the line where you are changing the value Commented Mar 3, 2012 at 14:15

4 Answers 4

1
$(this).change(function(){
 $.ajax({
      type:'POST',
      url: 'new.php',
      data: "idgs="+ idgs +"&newg="+ $(this).val(),
      success: function(data) {
        $('.right').html(data);

      }
    });
});
Sign up to request clarification or add additional context in comments.

Comments

1
var idg;
var newg;
$('input.readonly').live("click", function(){

    $(this).attr('readonly', false);

    $(this).change(function(){
        idgs=$(this).attr('id');
        newg=$(this).val();
        $.ajax({
            type:'POST',
            url: 'new.php',
            data: "idgs="+ idgs +"&newg="+ newg,
            success: function(data) {
                $('.right').html(data);
            }
        });

    })

}); 

This should do it, you where filling idg and newg with the default values, before they changed.

Comments

0

You need to use the val() method like this:

newg=$(this).val();

Comments

0

Try setting newg with .val() instead, and set it in the change handler to grab the updated value.

newg = $(this).val();

Also, you might find it more readable to pass an object to data, a la:

data: {
    'idgs': idgs,
    'newg': newg
},

Full code:

$('input.readonly').live("click", function () {
    $(this).attr('readonly', false);
    $(this).change(function () {
        var idgs = $(this).attr('id');
        var newg = $(this).val();
        $.ajax({
            type: 'POST',
            url: 'new.php',
            data: {
                'idgs': idgs,
                'newg': newg
            },
            success: function (data) {
                $('.right').html(data);
            }
        });
    })
});

Comments

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.