Solved

Javascript that creates a list of buttons

Posted on 2013-11-04
5
250 Views
Last Modified: 2013-11-25
I need to create a Javascript that creates a list of buttons with this characteristics:
The buttons are created from two different png-files - TheBlue.png and TheRed.png. They work as radio buttons in the sense that one and only one is blue at a particular time.

Each button has an id and a name (that is printed on the button).

Also, a click on a red will make that one "blue" instead plus call another script telling the id of the new blue button.

When the script starts, there are 2 arrrays with button ids and button names.

When the function has been created the buttons, it will end up on a html page at a certian tag.

Is that possible to create?
0
Comment
Question by:mdoland
  • 3
  • 2
5 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 39623564
What you need is actually to style radiobuttons as buttons.
Do you already use jQueryUI in your website?

If so this might be the best solution: http://jqueryui.com/button/#radio

It's exactly what you want, you just need to override the jQuery UI styles with your own which is easilly achieved by inspecting the elements with FireBug or Chrome dev tools.
0
 

Author Comment

by:mdoland
ID: 39623570
Is it true that I can override the jQuery UI? Could you describe how to do that in more detail please. I have an existing UI based on jQuery and was trying to remove the jQuery things and do it myself, but it feels very tough.
0
 

Author Comment

by:mdoland
ID: 39623593
This is how the existing UI looks like. What would I need to do to change the existing buttons with png-images showing one image for the active one and another image for the others?

$(function () {	
	var navbar = $('<div/>', {
		'data-role': "navbar",
		'id': "navbar-figures",
		'data-theme': "b",  
	});	

	
	var ul = $('<ul/>', {
		'id': "figures-list"
	});

    for (var i=0; i<figureId.length; i++) {
		if(i==0) { 
			$('<li/>', {			
				html: '<a onclick="validateFigur(this);" value="' + figureId[i] +'" id="' + figureId[i] +'" class="ui-btn-active ui-state-persist">' + figureName[i] + '</a>'
				
			}).appendTo(ul);
		} else {
			$('<li/>', {			
				html: '<a onclick="validateFigur(this);" id="' + figure[i] +'">' + figureName[i] + '</a>'
			}).appendTo(ul);
		}
	}			
	setFirstLegendTitle(figureName[0]);	
	ul.appendTo(navbar);
	$('#figures-list').listview('refresh');	
	$('#content-navbar').append(navbar);
	navbar.navbar();
	$('#content-navbar').trigger('create');	
})

Open in new window

0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 39623642
I'm not able to make a working sample only out of that code...

Can you give me url where I can see it working?
Also, I see neither button or ratio buttons they're... they're all links.

Anyway, here's a working sample where I use the above mentioned jQueryUI styled radio buttons. The first are the default style, the second have their style overridden (sorry about the colors :))
http://jsfiddle.net/GzNL7/1/
0
 

Author Comment

by:mdoland
ID: 39623677
Ok, well, isn't it sort of jQuery buttons. Anyway, is it somehow possible to change the look of it? Now the look comes from this:

      var navbar = $('<div/>', {
            'data-role': "navbar",
            'id': "navbar-indicators",
            'data-theme': "b",  

It is a box-looking thing there.
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

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

863 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

24 Experts available now in Live!

Get 1:1 Help Now