Solved

Javascript that creates a list of buttons

Posted on 2013-11-04
5
253 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

856 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