M
morellik
Dear all,
I'm a JS and english newbie (excuse me for my bad english) and I have
a problem in a function that I don't understand. I'm using prototype
framework.
I have a lot of checkbox, when I select for the first time a checkbox,
the function loadData doesn't
works properly: the other checkbox are disabled, the div block
appears, but in the Error Console I have "users has no properties".
If I select another checkbox, all works properly and so on. Only the
first time that I enter in the page and select a checkbox the
functions doesn't works properly. Starting from the second selection
all works well.
Where is the problem?
Thanks in adance
Enrico.
function unCheckAll() {
var form=$('signup');
var i=form.getElements('checkbox');
i.each(function(item) {
if (item.checked) item.checked=false
});
}
var askUsers=false;
var users;
function sendData() {
var myAjax = new Ajax.Request (
'askUsers',
{
asynchronous : true,
method : 'get',
onSuccess : function(transport) {
users=transport.responseText;
},
onFailure : function() { alert('Something went
wrong...') }
}
);
}
function loadData(id) {
if ($(id).checked) {
var form=$('signup');
var i=form.getElements('checkbox');
i.each(function(item) {
if (id!=item.id && item.checked) item.checked=false
});
$('enters').show();
$('message').innerHTML=askUsers;
if (! askUsers) {
sendData();
askUsers=true;
}
var u=users.split(',');
//alert(u);
$('username').disabled=false;
for (var i=0;i<u.length;i++) {
$('username').options = new Option(u, u);
}
}
else {
$('enters').toggle();
}
}
..
..
<body onLoad="unCheckAll();">
<div id="enters" style="display:none">
<select id="username" name="username" disabled></select>
</div>
..
..
<input type="checkbox" id="day_0" onClick="loadData(id);">
<input type="checkbox" id="day_1" onClick="loadData(id);">
<input type="checkbox" id="day_2" onClick="loadData(id);">
..
..
I'm a JS and english newbie (excuse me for my bad english) and I have
a problem in a function that I don't understand. I'm using prototype
framework.
I have a lot of checkbox, when I select for the first time a checkbox,
the function loadData doesn't
works properly: the other checkbox are disabled, the div block
appears, but in the Error Console I have "users has no properties".
If I select another checkbox, all works properly and so on. Only the
first time that I enter in the page and select a checkbox the
functions doesn't works properly. Starting from the second selection
all works well.
Where is the problem?
Thanks in adance
Enrico.
function unCheckAll() {
var form=$('signup');
var i=form.getElements('checkbox');
i.each(function(item) {
if (item.checked) item.checked=false
});
}
var askUsers=false;
var users;
function sendData() {
var myAjax = new Ajax.Request (
'askUsers',
{
asynchronous : true,
method : 'get',
onSuccess : function(transport) {
users=transport.responseText;
},
onFailure : function() { alert('Something went
wrong...') }
}
);
}
function loadData(id) {
if ($(id).checked) {
var form=$('signup');
var i=form.getElements('checkbox');
i.each(function(item) {
if (id!=item.id && item.checked) item.checked=false
});
$('enters').show();
$('message').innerHTML=askUsers;
if (! askUsers) {
sendData();
askUsers=true;
}
var u=users.split(',');
//alert(u);
$('username').disabled=false;
for (var i=0;i<u.length;i++) {
$('username').options = new Option(u, u);
}
}
else {
$('enters').toggle();
}
}
..
..
<body onLoad="unCheckAll();">
<div id="enters" style="display:none">
<select id="username" name="username" disabled></select>
</div>
..
..
<input type="checkbox" id="day_0" onClick="loadData(id);">
<input type="checkbox" id="day_1" onClick="loadData(id);">
<input type="checkbox" id="day_2" onClick="loadData(id);">
..
..