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 followers. Each message has a reply link which has been coded as follows <%=link_to "Reply" ,{},:href=>"#",:class => "replyMessage noBackgroundImage" ,:title =>"Click here to reply",:onclick=>"popup('popUpDiv_reply')"%>

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.

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