0

I have a click handler on a jQuery datatables table row - if you click a row a new dialog is launched. However i am having soem problems getting the ID which I need to pass to my ajax function which launches the pop up.

I have the line of code below:

var rowData = carTable.fnGetData(event.target.parentNode);

If I then do the following.

var json = JSON.stringify(rowData);

If I then alert(json); I get the following pop up

{"ExtensionData":{}, "CarRegNo" : "ABC 123", 
"CarNumber": "98765", "CarID" : 1234, 
"CarName" : "BMW", "CarFaults" : 2, 
"CarDealerID" : 16, "DealerName" : "WeSellCars"}

The only value I need is the 1234 from CarID? How can I easily get this value?

I tried the following so far with no luck - so without doing the JSON.stringify I just got the key from rowData - when I just alerted the key I could see all the different values, i.e CarID, CarRegNo - however then I tried to alret the actual value of CarID with the code below - but no response comes back - the browser just seems to hang.

        for (var key in rowData) {
            alert(key);
            if (key == 'CarID')
                alert(rowData[0][key]);
        }
1
  • You could simply use rowData.CarId but there is no reason for the code you show to hang. Commented Mar 7, 2013 at 9:44

2 Answers 2

2

Should literally be just:

var carId = rowData.CarId;

The rowData variable already contains the single object, and CarId is a property of it.

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

1 Comment

Works - simple - thanks - i was over complicating things. WIll mark as accepted when I can.
2

Then you need CarID from rowData:

var CarID = rowData.CarID

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.