Solved

Change text of current selected option on a DropDownCheckList element

Posted on 2014-01-21
4
646 Views
Last Modified: 2014-03-04
Hi.

I have a web application which uses DropDownCheckList element: http://dropdown-check-list.googlecode.com/svn/trunk/doc/dropdownchecklist.html

When user mark a checkbox, a prompt message appears asking for a numer.
How can I concatenate this number just after the text beside the just marked checkbox?

This is a snippet of my code:
		$("#proves").dropdownchecklist({
			onItemClick: function(checkbox, selector){
			var justChecked = checkbox.prop("checked");
				if (justChecked){
					num_autoritz_p = prompt("Número d'autorització:","");
					if (num_autoritz_p.length>0){
						codi_nou = checkbox.val();
						a_proves[codi_nou] = num_autoritz_p;
					}
					else
						checkbox.prop("checked",false);
				}
				else {
					codi_nou = checkbox.val();
					a_proves[codi_nou] = null;
					delete(a_proves[codi_nou]);
				}
	
			} // Fi function onItemClick
		}); // Fi definició dropdownchecklist

Open in new window


Thank you.
0
Comment
Question by:gplana
4 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
Comment Utility
Hi,

this should work:
$("#proves").dropdownchecklist({
			onItemClick: function(checkbox, selector){
			var justChecked = checkbox.prop("checked");
				if (justChecked){
					num_autoritz_p = prompt("Número d'autorització:","");
					if (num_autoritz_p.length>0){
						codi_nou = checkbox.val();
						a_proves[codi_nou] = num_autoritz_p;
                        oldText = $('#proves option[value="'+codi_nou+'"]').text();
                        newText =  oldText + "-" + num_autoritz_p;
                        $('#proves option[value="'+codi_nou+'"]').text(newText);
                        $('label[for="' +checkbox.prop("id") + '"]').text(newText);
					}
					else
						checkbox.prop("checked",false);
				}
				else {
					codi_nou = checkbox.val();
					a_proves[codi_nou] = null;
					delete(a_proves[codi_nou]);
				}
	
			} // Fi function onItemClick
		}); // Fi definició dropdownchecklist

Open in new window


Sample page:
http://jsfiddle.net/Rtvbx/

HTH
Rainer
0
 
LVL 15

Author Comment

by:gplana
Comment Utility
Thank you. Yes, it works, however I have two problems:

1. Is it possible also to remove the num_autoritz_p when user un-mark the checkbox?

2. If user marks the checkbox with the most large text, then the added number goes out of the control: scrollbars appear and number appeared on the page background instead of on the control's background.

Thanks.
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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 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

15 Experts available now in Live!

Get 1:1 Help Now