Please help me out with this, jquery is working well in w3schools but in my rails 2 app its getting error like check not defined Here is my html code:
Checkbox: <input class="category_select" title="3" name="subject_ids[]" onchange="check(11,this)" type="checkbox" value="6"/>
<input class="category_select" title="9" name="subject_ids[]" onchange="check(11,this)" type="checkbox" value="7"/>
<input class="category_select" title="6" name="subject_ids[]" onchange="check(11,this)" type="checkbox" value="8"/>
and the Jquery as follows
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.js">
function check(val,that) {
var total=parseInt(0,10);
$('.category_select').each(function(){
if($(this).is(':checked')==true)
total=total+parseInt($(this).attr('title'),10);
});
if (total > val){
$(that).removeAttr('checked');
alert('Total is greater than val !');
}else{
alert('Total is less than or equal to val !');
}
}
</script>
The above code works well , but when i insert it into my rails app its getting error , I dont know where I am going wrong. Any help is valuable
in rails 2 JQUERY is not supporting so i changed my script to Javascript as follows
<script type='text/javascript'>
function check_total(e,t){
value=parseInt(e);
var a=parseInt(0);
$$("input.category_select").each(function(e){1==e.checked&&(a+=parseInt(e.title))}),a>value?(alert("Total is greater than Total Subcategory Hours !"),t.checked=!1):a==value&&alert("Total is equal to Total Subcategory Hours !")}
</script>
Thanks for your answers. the above script worked for me