0

I’m trying to get the value of the first value pair from a form submission via AJAX. Here’s what the var Formdata looks like (id=4&name=somename&blah=blah). How do I get the id value of 4? As you can see I was trying several ways but had no luck. Any suggestion would be much appreciated, thanks in advance.

$("#updatetask").validate({     
    submitHandler: function() {
    var formdata = $('#updatetask').serialize();
    var fistkey = formdata.split("&",1);
    var tester = fistkey.slice(-1);
    alert(tester);
    /*
   $.post('/tasks/AJAXupdate', $('#updatetask').serialize(), function(data){
    var returnMsg = data.replace(/^\s+|\s+$/g, '');
    if (returnMsg == 'error'){
        alert(returnMsg+': Unable to update task.');
    }else{
        parent.$.fancybox.close();
    }
   });*/
return false;
    }       
});


});
user281867
  • 587
  • 3
  • 11
  • 21

1 Answers1

2

Can't you simply $('#updatetask :input:eq(0)').val() instead of serializing it and parsing the string?

shesek
  • 4,584
  • 1
  • 28
  • 27