mam taki problem: przez php generuje sobie checkboxy i do kazdego przypisuje funkcje. Funkcja ma za zadanie dopisac wartosc checkboxa do tablicy przy zaznaczeniu, a przy odznaczeniu usunąć tą wartość z tablicy - problem wydaje się być banalny jednak coś mi nie idzie...
Kod
<script type="text/javascript">
var url= new Array;
function array_search(what,array){
for(var i=0; i<array.length; i++){
if (what == array[i]){
return i;
}
else{
return false;
}
}
}
function maras(id){
var link = document.getElementById("generatedLink");
var actValue = document.getElementById(id).value;
var exists = array_search(actValue, url);
if (exists)
{
delete url[exists];
}
else
{
url.push(actValue);
}
//alert("exists = " + exists + "\r\nactValue = " + actValue + "\r\nurl = " + url + "\r\nurl.length = " + url.length);
link.setAttribute('href','/rss/generate/'+url+'.xml');
}
</script>
var url= new Array;
function array_search(what,array){
for(var i=0; i<array.length; i++){
if (what == array[i]){
return i;
}
else{
return false;
}
}
}
function maras(id){
var link = document.getElementById("generatedLink");
var actValue = document.getElementById(id).value;
var exists = array_search(actValue, url);
if (exists)
{
delete url[exists];
}
else
{
url.push(actValue);
}
//alert("exists = " + exists + "\r\nactValue = " + actValue + "\r\nurl = " + url + "\r\nurl.length = " + url.length);
link.setAttribute('href','/rss/generate/'+url+'.xml');
}
</script>
może mi ktoś powiedzieć, co robie źle? Jeżeli odznaczam pierwszy checkboxów które zaznaczałem, to mi się usuwa z tablicy url, a jeżeli już następny jakiś to niestety nie... będę wdzięczny za jakieś naprowadzenie.