On 2 February 2016 at 10:02, Naveed Alam <lists@ruby-forum.com> wrote:
> Hello,
>
> I want to calculate percentage marks of students using jquery, for this
> I tried the below code but its not working. I am very beginner in ruby
> on rails.
>
> <div class="label-field-pair">
> <label><%= t('obtained_marks') %></label>
> <div class="text-input-bg"><%= a.text_field :ob_marks, :id =>
> "ob_marks" %></div>
> <div class="extender"></div>
> </div>
> <div class="label-field-pair">
> <label><%= t('total_mark') %></label>
> <div class="text-input-bg"><%= a.text_field :total_mark, :id =>
> "total_mark" %></div>
> <div class="extender"></div>
> </div>
> <div class="label-field-pair">
> <label><%= t('percentage_marks') %></label>
> <div class="text-input-bg"><%= a.text_field :percentage, :id =>
> "percentage" %></div>
> <div class="extender"></div>
> </div>
>
> <script type="text/javascript">
> $(function() {
> $("#total_mark, #ob_marks").keyup(function() {
> var t = $("#total_mark").val();
> var o = $("#ob_marks").val();
> $("#percentage").val(o * 100 / t);
> })
> });
> </script>
A simple way to debug your code is to use the javascript alert
function to display values as they are calculated so, for example, at
the start of the function you could insert
alert("In function");
then after the line var t = ...
alert(t)
to check that the value of t is being calculated correctly. Then you
can work out where it is going wrong. Also, in firefox, open the
console window (Tools > Web Developer > Web Console) and reload the
page and it will tell you if there are any errors in the javascript.
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu6X%2B5ohOJsvU_un%2BBuiHrEDvqEzzKHqzD3bheCR0vPsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment