?
Solved

Change text of current selected option on a DropDownCheckList element

Posted on 2014-01-21
4
Medium Priority
?
736 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
[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
4 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 2000 total points
ID: 39799162
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
ID: 39799331
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

770 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