Advertisement

06.04.2008 at 01:36AM PDT, ID: 23455917
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

prototype.js appending a <label/> to an Element

Asked by rstaveley in JavaScript, Dynamic HTML (DHTML)

Tags: ,

I want to know if I'm doing the right thing.

Here's the requirement:

> On an onClick, I add radio buttons to a form with associated text input. The first click results in a checked radio button and subsequent radio buttons are not selected. The radio buttons have a label and the inputs all get appended to a DIV (actually a SPAN).

My JavaScript - shown in the code snippet - works with Prototype 1.6, but I had to do a workaround for IE (same for IE6 and IE7). The label has a 'for' attribute to associate it with the radio button. I suspect IE confuses the 'for' with the 'for' you might use in for loops. Firefox does not have that problem.

My workaround is quoting the 'for', which works but feels wrong. Quoting 'for' doesn't seem to break Firefox and makes it work on IE 6 and 7.

Is this the best thing to do?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
<form>
	<!-- ... etc ... -->
	<span id="input-span"><span style="color: orange">Questions need at least two options<br/></span></span>
	<input type="button" onclick="addOption('input-span','option');" value="Add an option"/><br/>
</form>
 
<script type="text/javascript">
// <![CDATA[
	var option_no = 1;
	function addOption(div,name) { // div is the name of a DIV or SPAN
		var item_no = option_no++;
		if (item_no == 1)
			$(div).update();
		$(div).appendChild(
			item_no == 1
			? new Element('input',{type: 'radio', name: name+'_selected', id: name+'_selected_'+item_no, value: item_no, checked: 'checked'})
			: new Element('input',{type: 'radio', name: name+'_selected', id: name+'_selected_'+item_no, value: item_no})
		);
		$(div).appendChild(
			new Element('label',{'for': name+'_selected_'+item_no}).update('Option '+item_no+' &nbsp; ')
		);
		$(div).appendChild(
			new Element('input',{type: 'text', name: name, size: 60, value: 'Item '+item_no})
		);
		$(div).appendChild(
			new Element('br')
		);
	}
// ]]>
</script>
[+][-]06.04.2008 at 11:00PM PDT, ID: 21716690

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: JavaScript, Dynamic HTML (DHTML)
Tags: JavaScript with Prototype 1.6, IE 6 and 7
Sign Up Now!
Solution Provided By: b0lsc0tt
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.05.2008 at 09:27AM PDT, ID: 21721303

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.05.2008 at 10:56AM PDT, ID: 21722216

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.05.2008 at 10:57AM PDT, ID: 21722230

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.05.2008 at 11:26AM PDT, ID: 21722503

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.05.2008 at 03:25PM PDT, ID: 21724615

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628