pbd22 wrote:
OK, I think I have figured out a more productive way to ask this
question (i hope). Could somebody show me how I could identify a
change on my form (select box, input field, textarea, etc) and assign
the new values to an associated array for each element. So, there will
be a selectbox[0], input[0], etc and selectbox[1], input[1], etc. My
attempts at this have been pretty ugly - lots of code.
Thanks for any help.
Well, if it works, does it matter if it's one or three lines of code? It
really shouldn't, especially if it makes for readable/maintainable code.
Maybe you should post the code that does work, so someone can help you
beautify/optimize it.
Op3racionalwww.op3racional.eu
OK, as you wish. Below is the way I had approached it:
function X() {
// Title box
var arrTitle = new Array(max_count.length);
var title_box = document.getElementById('title');
// Description box
var desc_box = document.getElementById('description');
var arrDesc = new Array(max_count.length);
// Category ddl
var cat_ddl = document.getElementById('category');
var arrCat = new Array(max_count.length);
// Category Month
var recorded_mo = document.getElementById('recorded_mo');
var arrRecMo = new Array(max_count.length);
// Category Day
var recorded_day = document.getElementById('recorded_day');
var arrRecDay = new Array(max_count.length);
// Category Year
var recorded_yr = document.getElementById('recorded_yr');
var arrRecYr = new Array(max_count.length);
// Language ddl
var lang_ddl = document.getElementById('language');
var arrLang = new Array(max_count.length);
// Access - private
var access = document.forms['uploadForm'].elements['access'];
var arrAccess = new Array(max_count.length);
// Tags - NEED TO PARSE FOR SPACES BETWEEN WORDS
var tags = document.getElementById('tags');
var arrTags = new Array(max_count.length);
// Video Location
var video_location = document.getElementById('coords');
var arrLocation = new Array(max_count.length);
// Privacy - comments
var comments =
document.forms['uploadForm'].elements['comments'];
var arrComments = new Array(max_count.length);
// Privacy - ratings
var ratings =
document.forms['uploadForm'].elements['ratings'];
var arrRatings = new Array(max_count.length);
// Privacy - embedding
var embedding =
document.forms['uploadForm'].elements['embedding'];
var arrEmbedding = new Array(max_count.length);
// Event handlers
var last_click;
new_link.onclick = function() {
var oID = this.id;
var oIND = oID.lastIndexOf("_") + 1;
var active = oID.substr(oIND);
title_box.value = "";
desc_box.value = "";
tags.value = "";
//alert(video_location.value);
video_location.value = defLoc; // REMOVE THIS
recorded_mo.options[0].selected = true;
recorded_day.options[0].selected = true;
recorded_yr.options[0].selected = true;
cat_ddl.options[0].selected = true;
lang_ddl.options[29].selected = true;
access[0].checked = true;
comments[0].checked = true;
ratings[0].checked = true;
embedding[0].checked = true;
//count starts at 2
for(i=2;i<=max_count.length;i++) {
if(i == active) {
// Fill Pre-Existing Values
if(arrTitle
)
title_box.value = arrTitle;
if(arrDesc)
desc_box.value = arrDesc;
if(arrTags)
tags.value = arrTags;
if(arrLang)
lang_ddl.options[arrLang].selected =
true;
if(arrCat)
cat_ddl.options[arrCat].selected =
true;
if(arrRecMo)
recorded_mo.options[arrRecMo].selected
= true;
if(arrRecDay)
recorded_day.options[arrRecDay].selected = true;
if(arrRecYr)
recorded_yr.options[arrRecYr].selected
= true;
if(arrAccess)
access[arrAccess].checked = true;
if(arrLocation)
video_location.value = arrLocation;
if(arrComments)
comments[arrComments].checked = true;
if(arrRatings)
ratings[arrRatings].checked = true;
if(arrEmbedding)
embedding[arrEmbedding].checked =
true;
title_box.onchange = function (){
arrTitle[last_click] = title_box.value;
}
desc_box.onchange = function (){
arrDesc[last_click] = desc_box.value;
}
tags.onchange = function (){
arrTags[last_click] = tags.value;
}
lang_ddl.onchange = function() {
arrLang[last_click] =
lang_ddl.selectedIndex;
}
cat_ddl.onchange = function() {
arrCat[last_click] =
cat_ddl.selectedIndex;
}
video_location.onchange() {
arrLocation[last_click] =
video_location.value;
}
recorded_mo.onchange = function() {
arrRecMo[last_click] =
recorded_mo.selectedIndex;
}
recorded_day.onchange = function() {
arrRecDay[last_click] =
recorded_day.selectedIndex;
}
recorded_yr.onchange = function() {
arrRecYr[last_click] =
recorded_yr.selectedIndex;
}
access[0].onclick = function() {
arrAccess[last_click] = 0;
}
access[1].onclick = function() {
arrAccess[last_click] = 1;
}
comments[0].onclick = function() {
arrComments[last_click] = 0;
}
comments[1].onclick = function() {
arrComments[last_click] = 1;
}
comments[2].onclick = function() {
arrComments[last_click] = 2;
}
comments[3].onclick = function() {
arrComments[last_click] = 3;
}
ratings[0].onclick = function() {
arrRatings[last_click] = 0;
}
ratings[1].onclick = function() {
arrRatings[last_click] = 1;
}
embedding[0].onclick = function() {
arrEmbedding[last_click] = 0;
}
embedding[1].onclick = function() {
arrEmbedding[last_click] = 1;
}
last_click = i;
}
}
}