Solved

JSON, JQuery inline menu

Posted on 2014-01-17
1
560 Views
Last Modified: 2014-01-17
Hello,

I am trying to building different menus from a database and attach them to different divs in a webpage.  I have the data being added correctly except that it is not inline.  I would like it to look like this:  "Overview | The One | " etc.  

I just can't see what I am doing wrong....

Thanks in advance...

My json is this:

{
    "rows": [
        {
            "id": "1",
            "abbr": "en",
            "data": [
                {
                    "textboxID": "1",
                    "text": "Overview"
                },
                {
                    "textboxID": "2",
                    "text": "The One"
                },
                {
                    "textboxID": "3",
                    "text": "Viewing"
                },
                {
                    "textboxID": "4",
                    "text": "Sorting"
                },
                {
                    "textboxID": "5",
                    "text": "What"
                },
                {
                    "textboxID": "6",
                    "text": "Contact"
                },
                {
                    "textboxID": "7",
                    "text": "About"
                }
            ]
        },
        {
            "id": "2",
            "abbr": "fr",
            "data": [
                {
                    "textboxID": "1",
                    "text": "Sommaire"
                },
                {
                    "textboxID": "2",
                    "text": "Le carreaux"
                },
                {
                    "textboxID": "3",
                    "text": "Visualiser"
                },
                {
                    "textboxID": "4",
                    "text": "Filtrage"
                },
                {
                    "textboxID": "5",
                    "text": "'My Profile'"
                },
                {
                    "textboxID": "6",
                    "text": "'Contacte'"
                },
                {
                    "textboxID": "7",
                    "text": "Autour"
                }
            ]
        }
    ]
}

Open in new window


My javascript is:

var url1 = "GetJson.php?what=2";
$.getJSON( url1, function(result1) {
		
				  
	$.each(result1.rows, function(m,val){
       var thesemenus =[];
       var $div2 = $('<div/>').appendTo("."+$.trim(result1.rows[m].abbr));
      $div2.attr('id', 'menuitem'+result1.rows[m].id);
	$div2.attr('class', 'menuitem');
	$.each(result1.rows[m].data, function(n,val){
	if(m==0){
    	thismenu = '<div  >|&nbsp;<a id="'+result1.rows[m].data[n].textboxID+'Menuitem" class="langmenu">'+result1.rows[m].data[n].text+'</a>&nbsp;|</div>';
	} else {
	 thismenu = '<div   >&nbsp;<a id="'+result1.rows[m].data[n].textboxID+'Menuitem" class="langmenu">'+result1.rows[m].data[n].text+'</a>&nbsp;|</div>';
	}
    thesemenus.push(thismenu);
		});

$(thesemenus.join("")).appendTo("#menuitem"+result1.rows[m].id);	
		});	
	 	
						 
});

Open in new window


And my CSS:

#menuitem div#menuitem  {
    display: inline-block;
	cursor:pointer;
	
	
}



.menuitem{ position:absolute;
top:80px;
width:100%;
margin-left:auto;
margin-right:auto;
font-family:Tahoma, Geneva, sans-serif;
font-size:16px;
color:gray;
z-index:9999;
	
}

Open in new window

0
Comment
Question by:1Cougar
1 Comment
 

Accepted Solution

by:
1Cougar earned 0 total points
ID: 39788727
Hello again,

I fixed my own problem.  Here it is if it can help anyone:

$.each(result1.rows[m].data, function(n,val){
thismenu = thismenu+'&nbsp;<a id="'+result1.rows[m].data[n].textboxID+'Menuitem" class="langmenu">'+result1.rows[m].data[n].text+'</a>&nbsp;|';
		});
		 thismenu = thismenu + '</div>';
		thesemenus.push(thismenu);
$(thesemenus.join("")).appendTo("#menuitem"+result1.rows[m].id);

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now