checking values of arrays
Okej i have two files kategorije.txt and podkategorije.txt. txt file
kategorije looks like:
1; kategorija1
2; kategorija2
3; kategorija3
and txt file podkategorija.txt looks like:
1;1; podkategorija1
2;1; podkategorija2
3;2; podkategorija3
4;3; podkategorija4
I already splitted everything here. 1st txt file i splitted to get
"kategorija1,kategorija2,kategorija3" and i filled dropdown with it and
2nd txt file i splitted so i have other dropdown filled with
"podkategorija1, podkategorija2, podkategorija3, podkategorija4" I also
splitted both files by ";" . In 1st file i use "1;2;3;" as index of that
category and i putted those numbers in value of "option" and in 2nd i
splitted by both ";" so i got two arrays "1;2;3;4;5;6" and "1;1;2;3". 1st
array i use same as in category for value of option. but 2nd array should
be link between two files. for example if user select "kategorija1"
dropdown of podkategorija should only show him "podkategorija1,
podkategorija2" and if user click "kategorija3" dropdown should show
"podkategorija4". I can solve this by checking selectedIndex but what i
need is that administrators wwho will work with this later can just add
new "x; kategorijaX" or
"x;x; podkategorijaX" and that will also be count in dropdowns w/o adding
any code. I tryed to explain as much as i could hope i made it
understandble. Idea is two compare two arrays but i dont know how... so
any explanation or example wohuld be appreciated.
<script type="text/javascript">
function readKategorije()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var txtFile = fso.OpenTextFile("kategorije.txt", 1, false, 0);
var fText = txtFile.ReadAll();
txtFile.Close();
fso = null
var array = fText.replace(/(\d;)/g,"").split("\n");
var sel = document.getElementById("dropdown2");
for (var i=0; i<array.length; i++)
{
var opt = document.createElement("option");
opt.innerHTML = array[i];
sel.appendChild(opt);
}
var array1 = fText.match(/^[^;]*(?=;)/mg);
var sel = document.getElementById("dropdown2");
for (var i=0; i<array1.length; i++)
{
opt.value = array1[i];
sel.appendChild(opt);
}
}
function readPodkategorije()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var txtFile = fso.OpenTextFile("podkategorije.txt", 1, false, 0);
var fText = txtFile.ReadAll();
txtFile.Close();
fso = null
var array2 = fText.replace(/(\d;)/g,"").split("\n");
var sel = document.getElementById("dropdown3");
for (var i=0; i<array2.length; i++)
{
var opt = document.createElement("option");
opt.innerHTML = array2[i];
sel.appendChild(opt);
}
var array3 = fText.match(/^[^;]*(?=;)/mg);
var sel = document.getElementById("dropdown3");
var zahtev = document.getElementById("zahtev");
for (var i = 0; i<array3.length; i++)
{
opt.value = array3[i];
sel.appendChild(opt);
zahtev.value = array3;
}
var array4 = fText.match(/^([^;]*;){2}/mg);
var zahtev = document.getElementById("zahtev");
for (var i = 0; i<array4.length; i++)
{
zahtev.value = array4;
}
}
No comments:
Post a Comment