Solved

Javascript that creates a list of buttons

Posted on 2013-11-04
5
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

730 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