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.
<%if (message.canpost == ‘Y’) or (message.is_user_default_channel ==
‘Y’) %>
</div>
</div>
<div style="padding:0px 0px 0px
0px;">
<textarea name=“message_reply”
id=“message_reply” maxlength =“400” style="overflow:auto;width:
100%;height:56px ;"onkeyup="checkPostFieldLength(message,‘remaining’,
400);"onkeydown="checkPostFieldLength(message,‘remaining’,
400);"onmouseout="checkPostFieldLength(message,‘remaining’,
400);“onclick=“showName(‘postedby’,‘message_reply’);”>
400
characters remaining
<%= submit_to_remote
“Post”,” Post ",
:update => “div3”,
:method => “post”,
:condition => “postMessage()”,
:before =>
“resetCharCount(‘remaining’);clearInnerHtml(‘div3’)”,
:loading =>
“Element.show(‘spinnerTimeLineDiv3’)”,
:loaded =>
“clearPostBox(document.getElementById(‘message_reply’));Element.hide(‘spinnerTimeLineDiv3’)”,
:url => {:controller=>“messages”,
:action
=> “post”},
:html => {:class => “btn”, :id =>
“submitButton”,:title=>“Click here to post.”} %>
</div>
<%end%>
I want to know how the two javascript methods can be called from the
view.
Thanks in Advance
Regards
Chandrika