Solved

Change text of current selected option on a DropDownCheckList element

Posted on 2014-01-21
4
719 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 500 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

717 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