skip to Main Content

I have a form, when the submit button is clicked I want to intercept the data and send it to an API. This code sends the first parameter, the Id, but none of the others.

    $('#myForm').submit(function (e) {
    e.preventDefault();
    $('#myForm').children('input').each(function () {
        $.get("/thisismyapiurl/", { Id: $('#dropdown').find(":selected").val(), paramName: this.Name, paramValue: this.Value });
    });
});

So the URL is generates is /thisismyapiurl/Id without the other two values. I want it to be /thisismyapiurl/Id/Name/Value

Why is it only sending the first parameter, what can I change so it sends all of them?

2

Answers


  1. Try to use jQuery to get name and value of your inputs:

    $.get("/thisismyapiurl/", { Id: $('#dropdown').find(":selected").val(), paramName: $(this).attr('name'), paramValue: $(this).val()});
    
    Login or Signup to reply.
  2. Try $(this) instead of this and .attr('name'):

    { Id: $('#dropdown').find(":selected").val(), paramName: $(this).attr('Name'), paramValue: $(this).attr('Value') });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search