Javascript call from view

Hello All,
I am working on a Microblogging application.(majorly written in Ruby
on Rails).(the application is similar to twitter) .There is a timeline
showing messages by the logged-in user and his/her
Each message has a reply link which has been coded as follows
<%=link_to “Reply” ,{},:href=>"#",:class => “replyMessage
noBackgroundImage” ,:title =>“Click here to

I have two javascript functions as follows defined seperately in an
application.js file.

function showName(inputName,textName){
var fieldName = document.getElementById(inputName);
document.getElementById(textName).value += ‘@’ + fieldName.value +
function decreaseName(inputname){
var fieldName = document.getElementById(inputname);
var totalLength = fieldName.length + 2;
var diff = 400 - totalLength;
return diff;

When I click on the reply link,a popup appears which has a text-area
and a post button.Beneath the textarea,appears the number of
characters remaining to be posted.Now when I click the reply link,I
want the showName function to be called so that the person to whom I
am replying is displayed in the text-area as '@username:'Also on the
reply click,my no of characters remaining should be shown as 400 -
@username: for which I have written the decreaseName function.

My reply block in view is as follows.

<%if (message.canpost == ‘Y’) or (message.is_user_default_channel ==
‘Y’) %>

<%=link_to "Reply" ,{},:href=>"#",:class => "replyMessage noBackgroundImage" ,:title =>"Click here to reply",:onclick=>"popup('popUpDiv_reply')",:success=>"showName('postedby','message_reply')"%>
<%=image_tag "/images/ ajax-loader.gif" %>
                                  <div style="padding:0px 0px 0px


<textarea name=“message_reply”
id=“message_reply” maxlength =“400” style="overflow:auto;width:
100%;height:56px ;"onkeyup="checkPostFieldLength(message,‘remaining’,

characters remaining

<%= submit_to_remote
“Post”,” Post ",
:update => “div3”,
:method => “post”,
:condition => “postMessage()”,
:before =>
:loading =>
:loaded =>
:url => {:controller=>“messages”,
=> “post”},
:html => {:class => “btn”, :id =>
“submitButton”,:title=>“Click here to post.”} %>


I want to know how the two javascript methods can be called from the

Thanks in Advance


First of all user Jquery it will make everything easier for you, Second
the code as a gist so is more readable