0

I need to filter using dynamic parameters from a form post. But I dont know how to send the parmeters with a dynamic generated name... see code below hope it explains my problem.

$('#kt_search').on('click', function(e) {
e.preventDefault();
var frm_data = $('#searchFrom').serializeArray();
$.each(frm_data, function(key, val) {

myData.comercial    = 23; //THIS WORKS

myData.val.name     = val.value; // THIS IS INCORRECT
});

table.table().draw();
}); 
2

1 Answer 1

1

Assuming val.name holds the name of the property, you can access the dynamic property like so:

myData[val.name]

So, to set the value:

myData[val.name] = val.value;

Here is a fiddle demo: https://jsfiddle.net/zephyr_hex/o98ykn72/4/

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

6 Comments

myData[val.name] = val.value; in console.log this shows the parameters with the value but how to I get the value in the posted file?
here is my console.log cliente: "" comercial: "24" end: "" hora: "" orderid: "" produccion: "" start: "" titulo: ""
so in the destination php file I would use $post_comercial = $_REQUEST["comercial"]; $post_estado = $_REQUEST["estado"]; but its not working what am I missing
when a field is empty I get an error: Uncaught TypeError: Cannot read property 'length' of undefined at _fnAjaxUpdateDraw (datatables.bundle.js:4126)
@vance = seems like you have several other issues going on, and you may need to work through them one by one. The answer I've posted above should resolve the question in your post.
|

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.