I am finding that this may not be possible with JavaScript, but I thought I would ask. Perhaps someone has another approach that would work just as well.
Background –
I have a ColdFusion script which uses a loop to create multiple variables. The number of variables affects the variable’s name and can vary from use to use. For example if 4 is selected; the loop happens four times, there would be a variable created for Info1, Info2, Info3, and Info4 as well as a Title1, Title2, etc and several other variables with corresponding numbers as well. This part works fine, and it passes to the next script or on to our DB as well.
My dilemma –
I commonly use JavaScript to setup a validation against my ColdFusion. This allows me to do an Alert() popup when a field in a table is unanswered. The trick is in this example I need the variable declared in the JavaScript to adjust according to the number used in the CFLoop. Is that even possible in JS?
Example –
The actual validation I use contains a lot more checks, but this is the core where my problem lies. Qform.Info.value can I dynamically alter this variable to coincide with the ‘i’ in the For loop?Code:function validateForm() { var AlertMe=0; var ValMessage=""; for (i=1;i<=Qform.count.value;i++) { var ValInfo=""; if (Qform.Info.value == "") {var ValInfo="Aditional Information"+i;AlertMe=1;} if (ValInfo != ""){if (ValMessage != ""){ValMessage += "\n";};ValMessage += ValInfo;} } if (AlertMe == 1) {alert("The following are required fields -\n" + ValMessage + "");return false;} return true; }
Any help would be great. An alternate method suggestion would be okay as well.



Reply With Quote

Bookmarks