Advertisement

03.27.2008 at 10:26AM PDT, ID: 23274890
[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!

7.4

How to clone a selectedIndex.text and best practice to append it...

Asked by dtreadway7 in Dynamic HTML (DHTML), JavaScript, Miscellaneous Web Development

Tags: ,

I have a dynamic form. The form is a set of drill-down select boxes [x3]. Each selectedIndex value is written to a corresponding div, then retrieved with a very nasty set of (innerHTML) swapping. To add to the nastiness, I have to use a simple sniffer (if(document.all)) and a lot of (obj.prentNode.childNodes[0].innerHTML) to make it work at all.

I would like to get away from having to use the object.parent references and use some (getElement) if possible. I would also like to use clone instead of innerHTML. The values i am copying do not need to have internal properties preserved so clone should make a great candidate. Problem is, I can't get clone to work on the (selectedIndex.text). I can only get "innerHTML" to work.

After all of these fields are filled out or, selected, their values will be stored in the parent ROW of this form. So, again I will need to a good way to reference that without using a lot of parentNode.parentNode..etc.

I am familiar with returning an object node types, but whats the best way to do it when the your current object is say childNode[13] (in IE) and childNode[14] in FF?    


Could I get a hand? Thanks in advance: 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:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Untitled</title>
<script>
  var arrItems1 = new Array();
  var arrItemsGrp1 = new Array();
  
        arrItems1[3] = "= (equal to St1)";
        arrItemsGrp1[3] = 1;
        arrItems1[4] = "= (equal to St2)";
        arrItemsGrp1[4] = 1;
        arrItems1[5] = "= (equal to St3)";
        arrItemsGrp1[5] = 1;
        
        arrItems1[6] = "= (equal to Emp1)";
        arrItemsGrp1[6] = 2;
        arrItems1[7] = "= (equal to Emp2)";
        arrItemsGrp1[7] = 2;
        
        arrItems1[0] = "Planes";
        arrItemsGrp1[0] = 3;
        arrItems1[1] = "Ultralight";
        arrItemsGrp1[1] = 3;
        arrItems1[2] = "Glider";
        arrItemsGrp1[2] = 3;
 
  var arrItems2 = new Array();
  var arrItemsGrp2 = new Array();
  
        arrItems2[21] = "747";
        arrItemsGrp2[21] = 0;
        arrItems2[22] = "Cessna";
        arrItemsGrp2[22] = 0;
        
        arrItems2[31] = "Kolb Flyer";
        arrItemsGrp2[31] = 1;
        arrItems2[34] = "Kitfox";
        arrItemsGrp2[34] = 1;
        
        arrItems2[35] = "Schwietzer Glider";
        arrItemsGrp2[35] = 2;
        
        arrItems2[99] = "Chevy Malibu";
        arrItemsGrp2[99] = 5;
        arrItems2[100] = "Lincoln LS";
        arrItemsGrp2[100] = 5;
        arrItems2[57] = "BMW Z3";
        arrItemsGrp2[57] = 5;
        
        arrItems2[101] = "Full-Time";
        arrItemsGrp2[101] = 3;
        arrItems2[102] = "Part-Time";
        arrItemsGrp2[102] = 3;
        
        arrItems2[103] = "Freight Train";
        arrItemsGrp2[103] = 4;
        arrItems2[104] = "Passenger Train";
        arrItemsGrp2[104] = 4;
        
        arrItems2[105] = "Value";
        arrItemsGrp2[105] = 6;
        arrItems2[106] = "Value2";
        arrItemsGrp2[106] = 6;
        
        arrItems2[200] = "Los Angelas Class";
        arrItemsGrp2[200] = 7;
        arrItems2[201] = "Kilo Class";
        arrItemsGrp2[201] = 7;
        arrItems2[203] = "Seawolf Class";
        arrItemsGrp2[203] = 7;
 
        // Function for the 1st drop-down                       
 
         function selectChange(control, controlToPopulate, ItemArray, GroupArray) {
    var myEle;
    var x;
 
    for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
                
                if(document.all){
                       var select1Dump = control.parentNode.childNodes[7]
                                         var select2Dump = control.parentNode.childNodes[8]
                   } else {
                       var select1Dump = control.parentNode.childNodes[7]
                                         var select2Dump = control.parentNode.childNodes[9]
                   }
                
                  if (control.name == "firstChoice"){
                                
                                alert(control.options[control.selectedIndex].text);
                                var control1Text = control.options[control.selectedIndex].text;
 
 
                        select1Dump.innerHTML = control1Text;  
                
                 } else if (control.name == "secondChoice"){
                 
                 
                    alert(control.options[control.selectedIndex].text);
                                        var control2Text = control.options[control.selectedIndex].text;
                        select2Dump.innerHTML = control2Text;  
                 } 
        
        
    myEle=document.createElement("option");
    theText=document.createTextNode("[SELECT]");
    myEle.appendChild(theText);
    myEle.setAttribute("value","0");
    controlToPopulate.appendChild(myEle);
  
    for ( x = 0 ; x < ItemArray.length; x++ ) {
      if ( GroupArray[x] == control.value ) {
        myEle = document.createElement("option") ;
        myEle.setAttribute("value",x);
        var txt = document.createTextNode(ItemArray[x]);
        myEle.appendChild(txt)
        controlToPopulate.appendChild(myEle)
      }
    }
 
  }
 
        //Role: Build Dynamic form pieces from drop-down 3  
        function selectChange3(control3, op) {
 
                                if(document.all){
                       var newDiv = control3.parentNode.childNodes[10];  
                                         var select1Dump = control3.parentNode.childNodes[7];
                                         var select2Dump = control3.parentNode.childNodes[8];
                             var formDumpDiv3 = control3.parentNode.childNodes[9]; 
                   } else {
                       var newDiv = control3.parentNode.childNodes[13];  
                                         var select1Dump = control3.parentNode.childNodes[7];
                                         var select2Dump = control3.parentNode.childNodes[9];
                             var formDumpDiv3 = control3.parentNode.childNodes[11]; 
                   }
                         
                                 
        if (op == 1 && control3.value == "101") {
                         newDiv.innerHTML = "";
                } 
    else if (op == 2 && control3.value == "102")  {   
        newDiv.innerHTML = "<input type='text' size='10' name='State' value='Part-Time'>";
    }
    else if (op == 3 && control3.value == "103") {
        newDiv.innerHTML = "<input type='text' size='20' value='3'>";
    } else {
                    newDiv.innerHTML = "";
                }
                
                //newDiv.innerHTML = control3.options[control3.selectedIndex].text
                formDumpDiv3.innerHTML = select1Dump.innerHTML + "," + select2Dump.innerHTML + "," + control3.options[control3.selectedIndex].text
                //formDumpDiv.innerHTML = control3.options[control3.selectedIndex].text
        
  }
 
</script>
</head>
 
<body>
 
<form name="" action="#" method="post" style="display:inline;margin:0px;">
         
<div id="selectParent">
                                        
Field:<select id='firstChoice' name='firstChoice'  style="clear:right;" onchange='selectChange(this, secondChoice, arrItems1, arrItemsGrp1)'>
<option value='0' selected>[SELECT]</option>
<option value='1'>Employment</option>
<option value='2'>State</option>
<option value='3'>Other</option>
</select>
                                        
Operator:<select id='secondChoice' name='secondChoice'  style="clear:right;" onchange='selectChange(this, thirdChoice, arrItems2, arrItemsGrp2)'>
<option value='0' selected>[SELECT]</option>
</select>
         
Compare with:<select id='thirdChoice' name='thirdChoice'  style="clear:right;" onChange="selectChange3(this, this.selectedIndex);">
<option value='0' selected>[SELECT]</option>
</select>
                                        
                                        
<div id="formDump1" style="display:none;clear:right;border:1px red solid;"></div>
 
<div id="formDump2" style="display:none;clear:right;border:1px red solid;"></div>
 
<div id="formDump3" style="clear:right;border:1px red solid;"></div>
<div id="extraField"  style="clear:right;top:-30px;"></div>
                                        
<div style="height:2px; width:1px;"></div>
<div class="doneImg"  onclick="hideRow(this);"></div>
 
</div>
 
</form>
 
</body>
</html>
 
Keywords: How to clone a selectedIndex.text an…
 
Loading Advertisement...
 
[+][-]03.27.2008 at 08:13PM PDT, ID: 21227739

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.28.2008 at 05:56AM PDT, ID: 21229891

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.28.2008 at 06:21AM PDT, ID: 21230102

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.28.2008 at 06:28AM PDT, ID: 21230167

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.28.2008 at 06:52AM PDT, ID: 21230354

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.28.2008 at 07:58AM PDT, ID: 21230994

View this solution now by starting your 30-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: Dynamic HTML (DHTML), JavaScript, Miscellaneous Web Development
Tags: javascript, DHTML, IE6, IE7, FF, Safari
Sign Up Now!
Solution Provided By: dtreadway7
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628