Solved

Javascript that creates a list of buttons

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

760 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

21 Experts available now in Live!

Get 1:1 Help Now