Posts Tagged javascript
“Changing the class of a div using rails NOT JS”
Consider we need to change the class of a particular DIV/SPAN , I was wondering how we could have done using some default rails method and NOT Javascript as what we can do in Javascript the same we can do using Rails but in lesser time and number of lines of code.
Using google with the correct key words resulted in the following
Javascript
function change(id, newclass)
{
identity=document.getElementById(id);
identity.className=newclass;
}
Rails
page["task_#{params[:id]}”].toggle_class_name “completed”
Add comment December 9, 2008
“Javascript made me feel like a IDIOT”
Today I was doing some javascript checks so that my regular price remains
always greater than the discounted price .
I check with normal arithmetic functions “==,<,>” to the $(“field_name”).value
and thought it has worked because that what was taught to me in my schools
that value 1 > value 2 returns true/false.
But all my prettiest school teachers were proven wrong by javascript.
I realized after releasing the code that
11> 10 => true
99.99 > 99.98 => true
212 > 212.21 => false
but they were also checking the number of digits.
So when I gave
10 > 9 => false(It failed) …hmm even I had the same reaction!!!!
Man , what the S**T cum on how can this happen , then I thought
bro need to check javascripts arithmetic handlers once again ,
over there I came accross parseFloat and other functions.
check the link for more details
For the next two days I shall be wearing the “I was wrong ” Tshirt….
Technorati Tags: rails, ruby on rails, ror, ruby, javascript, parseFloat to check the arithemetic methods properly, comparing numbers in javascriptrails, ruby on rails, ror, ruby, javascript, parseFloat to check the arithemetic methods properly, comparing numbers in javascript
1 comment July 2, 2008
“Run Ruby on a JavaScript interpreter?”
&lt;script type="text/ruby"&gt;class Pi def initialize @a = 355.0 end def calc b = 113.0 return @a / b endPI = 'PI is about' endputs Pi::PI
puts Pi.new.calc &lt;/script&gt;
&lt;body onload="Print(); new function().runFromScriptTag('/compileRuby.cgi')"&gt;
Add comment April 17, 2008