View Full Version : Javascript help needed
coolguyraj
11-10-2005, 11:23 AM
Hi...
I am stuck up with a problem..
I wanted some help on polling software in javascript.
I have a web page in HTML.
I want to incude a online poll for selecting 15 holidays out of the alloted 20.
I will have a list with the holiday names a user should be able to select the check box against it but it should be limited to 15.
Also a user should be able to vote only once.
I should be able to see the results in no of votes and the percentage against each holiday.preferably in a different page it should be password protected.
The main aim of the software is to help deciding the holiday based on user inputs.
Please help me...
Thanks in advance.
Coolguyraj.
Garadon
11-10-2005, 11:36 AM
That is more server side(PHP,ASP,...) and not javascript. javascript can't save information on the server.
Only first of you goals is to be done with javascript, the limit of the checkboxes checked
<script type="text/javascript">
var maxA=15;//maximum allowed
var obj=[];
function checkT(){
var q=0;
for(var i=0;i<obj.length;i++){
disen(obj[i],false);
q=(obj[i].checked)?q+1:q;
}
if(q==maxA){
for(var i=0;i<obj.length;i++){
disen(obj[i],(!obj[i].checked))
}}}
function disen(o,b){
o.setAttribute('disabled',b);
return
}
onload = function(){
var inp = document.getElementById('container').getElementsByTagName('input');
for(var i=0;i<inp.length;i++){
if(inp[i].type=='checkbox'){
inp[i].onclick=checkT;
obj[obj.length]=inp[i];
}}}
</script>
...
<div id="container">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
... and so on till 20 checkboxes
</div>
The rest is to be done with a server-side application
coolguyraj
11-10-2005, 12:34 PM
Thanks a lot for your help...
Still i am not able to understand it properly,it would be helpful if you could explain me in a broader sense.
I understood the code for limiting the check boxes to 15,But once i have the check boxes checked and the "vote" or "submit" button is pressed it should calculate the percentage of votes.
Can i do it without a database.
Hope you will help me.
Thanks.
Coolguyraj.
As we said, that is to be done only with a server-side application, not with a client-side one. Javascript alone can not read/write/store data.
Pyth007
11-10-2005, 08:36 PM
The only way you would be able to do this in js is if everyone used the same page... and I don't mean the same html file, but rather the exact same page on the same computer at (or near) the same time. JS is client-side, which means that the only info stored or passed on has to come from the user's computer. If the user closes the browser window or even goes to a different site, all of that info would be lost (unless the client's computer stores that info in a cookie or temp. internet file). But then the info cannot be passed to some other user on a different computer.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.