This script exists to first break down existing JavaScript variables in to arrays. The problem is that when I attempt to make the script more dynamic by selecting the key number by using a parameter in place of a static number it will only execute the function on the first key (that would be the_id_split[0]). This means only the array's first key value is properly executed. If the first property in the original JavaScript variable is 'border-color' then only the border-color will have it's associated CSS value inserted in to the text field. You can test this by switching the order of the property/values on line 9 and then re-requesting the page (reload/refresh will not result in the removal of existing values so I always just press the go button to reduce confusion).
Any way I've made another attempt at being a bit more static by creating a coditional variable on lines 17~20 and that did not work either. I also tried applying the this approach that successfully worked on line 49 however it's clear it will not work with an array and associated keys. Lastly I also manually tried using the_id_split[split_number] on lines 32~41 where the variable the_property is currently being used right now.
So right now on lines 32~41 I need the the_property variable to select the correct array's key which always defaults to the_id_split[0]. When I call it on line 52 using insert_variables_exec(selector, '2'); the the_property variable should be equivalent to the_id_split[2]. When this correctly works if there are four property/value sets in the JavaScript variable as there are in this example row 4 should have the second, third, fourth, and fifth (left to right) all have values inserted in to each field.
Suggestions for dynamically choosing an array's key would be most helpful at this point in time!
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>Test Page</title><html><head><script type="text/javascript">//<![CDATA[window['ii41'] = 'background-color: #fff; border-color: #cc6; background-image: url(general/11/001.gif); color: #cc9;'; function insert_variables_exec(selector, split_number){ var the_id1 = 'ii' + selector + '1'; var the_id2 = this[the_id1]; var the_id_split=the_id2.split(';'); if (split_number == '0') { var the_property = the_id_split[0];} else if (split_number == '1') { var the_property = the_id_split[1];} else if (split_number == '2') { var the_property = the_id_split[2];} else if (split_number == '3') { var the_property = the_id_split[3];} var the_property2 = 'the_id_split[' + split_number + ']'; //var the_property2 = this[the_property1]; alert(the_id_split[1]); alert(the_id_split[2]); alert(the_id_split[3]); //bg-color if (the_property.indexOf('#') == '18') {var temp_var = the_property.split('#'); document.getElementById('ce' + selector + '1').value = temp_var[1];} //bg-img else if (the_property.indexOf('url(general/') == '18') {var temp_var1 = the_property.split('url(general/'); var temp_var2 = temp_var1[1].split('.gif)'); document.getElementById('ce' + selector + '2').value = temp_var2[0];} //border-color else if (the_property.indexOf('#') == '14') {var temp_var = the_property.split('#'); document.getElementById('ce' + selector + '3').value = temp_var[1];} //color else if (the_property.indexOf('#') == '7') {var temp_var = the_property.split('#'); document.getElementById('ce' + selector + '4').value = temp_var[1];} else {alert('eh nothing?' + the_property);}} function insert_variables(selector){ var the_selector1 = 'ce' + selector + '2'; var the_selector2 = this[the_selector1]; insert_variables_exec(selector, '0'); insert_variables_exec(selector, '2');}//]]></script><style type="text/css">b.bad {color: #f00;}b.good {color: #0f0;}form {height: 300px; overflow: auto; width: 80%;}</style></head><body> <form><fieldset><input id="ce00" name="ce00" type="text" value="" /><input id="ce01" name="ce01" type="text" value="" /><input id="ce02" name="ce02" type="text" value="" /><input id="ce03" name="ce03" type="text" value="" /><input id="ce04" name="ce04" type="text" value="" /><br /><input id="ce10" name="ce10" type="text" value="" /><input id="ce11" name="ce11" type="text" value="" /><input id="ce12" name="ce12" type="text" value="" /><input id="ce13" name="ce13" type="text" value="" /><input id="ce14" name="ce14" type="text" value="" /><br /><input id="ce20" name="ce20" type="text" value="" /><input id="ce21" name="ce21" type="text" value="" /><input id="ce22" name="ce22" type="text" value="" /><input id="ce23" name="ce23" type="text" value="" /><input id="ce24" name="ce24" type="text" value="" /><br /><input id="ce30" name="ce30" type="text" value="" /><input id="ce31" name="ce31" type="text" value="" /><input id="ce32" name="ce32" type="text" value="" /><input id="ce33" name="ce33" type="text" value="" /><input id="ce34" name="ce34" type="text" value="" /><br /><input id="ce40" name="ce40" type="text" value="" /><input id="ce41" name="ce41" type="text" value="" /><input id="ce42" name="ce42" type="text" value="" /><input id="ce43" name="ce43" type="text" value="" /><input id="ce44" name="ce44" type="text" value="" /><br /><input id="ce50" name="ce50" type="text" value="" /><input id="ce51" name="ce51" type="text" value="" /><input id="ce52" name="ce52" type="text" value="" /><input id="ce53" name="ce53" type="text" value="" /><input id="ce54" name="ce54" type="text" value="" /></fieldset></form> <div><a href="javascript: insert_variables('4');">insert_variables 4</a></div></body></html>