Welcome visitor
* Login
* Register
It is currently January 17th, 2019, 12:32 am
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » JavaScript



Post new topic Reply to topic  [ 3 posts ] 
Author Message
  evaluate checkboxes with Javascript
PostPosted: February 22nd, 2009, 12:31 am 

Posts: 46
Hi there, im having a little trouble evaluating some checkboxes, so any help is gladly appreciated.

My form, briefly is as follows:
<form>
january &nbsp; <input type="checkbox" name="month">
  <br><br>
february &nbsp; <input type="checkbox" name="month">
  <br><br>
march &nbsp; <input type="checkbox" name="month">
  <br><br>
...and so on

<input type="button" onclick="evaluate()" value="select">
</form>

And what i need to do is evaluate wich months were checked so i can show the info related to those months, and this is where im having problems. This is the code i have as far as i have figured it out:
<script type="text/javascript">
function evaluate(){
var limit=document.getElementsByName('month').length;
    for (i=0; i<=limit-1; i++){
        if (document.getElementsByName('month')[i].checked){
            ¿¿¿???
        }
    }
}
</script>

Any corrections or suggestions are welcomed!


Top
 Profile  
 
  Re: evaluate checkboxes with Javascript
PostPosted: February 22nd, 2009, 12:42 am 
User avatar

Posts: 81
to keep what you have almost the same, i would sugest u to use the 'value' for each checkbox, see:
january &nbsp; <input type="checkbox" name="month" value="01">
february &nbsp; <input type="checkbox" name="month" value="02">

then create an array with the info for the selected months:
function evaluate(){ 
var a=document.getElementsByName('month').length;
var j=0;
var selected_mo= new Array();
    for (i=0; i<=a-1; i++){
        if (document.getElementsByName('month')[i].checked){
            selected_mo[j]= document.getElementsByName('month')[i].value;
            j++;
        }
    }
}

hope this helps, cheers


Top
 Profile  
 
  Re: evaluate checkboxes with Javascript
PostPosted: February 22nd, 2009, 1:04 am 

Posts: 46
Sure, thank you so much!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

FORUMS » Client Side » JavaScript


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron