what i need
i need to show the count on icon .
i need to make dynamic div from input using array using javascript.
array structure
Array
(
[0] => Array
(
[id] => 50615
[des] => PHARMA Pro&Pack Expo 2015 is organized by IPMMA and will be held at Mumbai, the economic capital of India. This show helps the exhibitors from all ove
[membership] => 0
[name] => Pharma Pro&Pack Expo
[abbr_name] => Pharma Pro&Pack Expo
[paid] => 0
[event_wrapper] => 33587
[event_samll_wrapper] => http://im.gifbt.com/industry/27-350x210.jpg
[event_url] => pharma-propack-expo
[website] => http://www.pharmapropack.com
[eventType] => 1
[venue_name] => Bombay Convention & Exhibition Centre (BCEC)
[startDate] => 2015-05-13
[endDate] => 2015-05-15
[city] => Mumbai
[country] => India
[country_url] => india
[country_shortname] => India
[industry_id] => 27
[industry_name] => Medical & Pharmaceutical
[industry_url] => medical-pharma
[event_status] =>
[total_visitors] => 144
[total_exhibitor] => 0
[total_speakers] => 0
)
[1] => Array
(
[id] => 57271
[des] => The Iphex is a well acknowledged event in the pharmaceutical and healthcare industry and with the presence of pharmaceutical products and equipments,
[membership] => 0
[name] => Iphex
[abbr_name] => Iphex
[paid] => 0
[event_wrapper] => 41539
[event_samll_wrapper] => http://im.gifbt.com/industry/27-350x210.jpg
[event_url] => iphex
[website] => http://iphex-india.com/
[eventType] => 1
[venue_name] => Bombay Exhibition Centre
[startDate] => 2015-05-13
[endDate] => 2015-05-15
[city] => Mumbai
[country] => India
[country_url] => india
[country_shortname] => India
[industry_id] => 27
[industry_name] => Medical & Pharmaceutical
[industry_url] => medical-pharma
[event_status] =>
[total_visitors] => 134
[total_exhibitor] => 120
[total_speakers] => 0
)
[2] => Array
(
[id] => 175534
[des] => The TENSYMP, organized by the CimlGlobal will take place from 13th May to the 15th May 2015 at the Courtyard by Marriott, India in Ahmedabad, India. T
[membership] =>
[name] => TENSYMP Ahmedabad
[abbr_name] => TENSYMP Ahmedabad
[paid] =>
[event_wrapper] =>
[event_samll_wrapper] => http://im.gifbt.com/industry/40-350x210.jpg
[event_url] => tensymp-ahmedabad
[website] => http://www.tensymp2015.org/
[eventType] => 2
[venue_name] => Gujarat International Finance Tec-City
[startDate] => 2015-05-13
[endDate] => 2015-05-15
[city] => Ahmedabad
[country] => India
[country_url] => india
[country_shortname] => India
[industry_id] => 40
[industry_name] => Scientific Instruments
[industry_url] => scientific-instruments
[event_status] =>
[total_visitors] => 3
[total_exhibitor] => 0
[total_speakers] => 3
)
js code
var desktop="/app.php/notificationdetail";
var http = new XMLHttpRequest
url = desktop,
params = url;
http.open("POST", url, !0), http.setRequestHeader("Content-type", "application/json; charset=UTF-8"), http.setRequestHeader("Content-length", params.length), http.setRequestHeader("Connection", "close"),
http.onreadystatechange = function() {
if (4 == http.readyState && 200 == http.status) {
var obj=http.responseText;
alert(typeof obj);//string
var parsed = JSON.parse(obj);
for (var c in obj) {
var newElement = document.createElement('div');
newElement.id = obj[c]; newElement.className = "notification";
newElement.innerHTML = obj[c];
document.body.appendChild(newElement);
}
}
}, http.send(params);
problem
- i need to find length of array like if use php counts then it shows 2 array whereas if i use .length() in js it doesn"t return required result.
o/p should should be
- count in notification should be 2 using javascript .
- i need to show ['id'],['name'],['city'] in dynamic div.
i have tried using for loop
for (var x=0; x<obj.length; x++)
{
var name= obj[x].name;
console.log(name);//outputs : undefined
}