0

i am creating a system in which there is a table and data is displayed dynamically in the table now for every row there is checkbox! what actually i am doing this when the user check on specific rows through checkbox i want to get that whole row in the format of something like given below e.g

    object [
        0: {
        brandname:"brand_value",
        createdon:"createdon_value"
        .
        .
        .
             },
        {
    1:brandname:"brand_value",
        createdon:"createdon_value"
        .
        .
        .
        }
        ]

now what i done so far

PHP

 $obj = "{".$r['brand'].",".$r['production_date'].",".$r['expiry_date'].",".$r['madein'].",".$r['status'].",".$r['batch_code'].",".$r['created_on']."}";

echo "<th id='not2'><input type='checkbox' name='checkedvalues' value='".$obj."'/> </th>";

now what i am doing is i am creating an object(which is not working as i want it to be) and echoing out the value in every checkbox value attribute so that i can get that checked values in jquery

JQuery Function

$.each($("input[name='checkedvalues']:checked"), function(){
                    selectedvalues.push($(this).val());
                });

this is actually where the problem begins i need unique index with separated key and values e.g index 0 should contain data with key being brand and a value against it! because i need to access the the keys associated with an index individually ,now the problem!

selectedvalues.forEach(function(item, index, selectedvalues) {
                console.log(index , item);
            });

when i print this array it is showing me in the following format

 0 {asdsa,2017-09-05,2017-09-13,asda,asdsa,WRCTG8O,2017-09-27}
    1 {asdsa,2017-09-05,2017-09-13,asda,asdsa,WRCAbc2,2017-09-27}

it is actually creating an index and assigning all the values to that index whereas i want to access the values in an index using keys e.g 0 index value through key ,which e.g is brand="brand_Value" ! just like we do in php we create an associative array an and in key we put index and in value we put another array with keys and values, any help?

1 Answer 1

1

php

$obj = json_encode($r);

js

var ary = [];
ary['key'] = JSON.parse($(this).val());
selectedvalues.push(ary);
Sign up to request clarification or add additional context in comments.

9 Comments

this code is assigning key to every value where as i want to make keys and values inside the value so that i can access them using names
you can set key for different value
0 [key: "{asdsa,2017-09-05,2017-09-13,asda,asdsa,S4AQ9AR,2017-09-27}"]
this is what it is returning whereas i want to access e.g value of S4AQ9AR i dont have any way of doing it right now!
you can use parse json to send multiple value
|

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.