?
Solved

Javascript that creates a list of buttons

Posted on 2013-11-04
5
Medium Priority
?
258 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 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

800 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