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 id="userLinks"class="reply">
<%=link_to "Reply" ,{},:href=>"#",:class =>
"replyMessage
noBackgroundImage" ,:title =>"Click here to
reply",:onclick=>"popup(''popUpDiv_reply'')",:success=>"showName(''postedby'',''message_reply'')"%>
</div>
<input type="hidden" name="postedby"
id="postedby" value="<%=h
message.posted_by_name %>"/>
<div id="popUpDiv_reply" class="replypopUpDiv"
style="display:none;padding:0px 0px 0px 0px;">
<div id="spinner_page_col"
style="margin:0px 0px;position:absolute;display:none;">
<%=image_tag "/images/
ajax-loader.gif" %>
</div>
<div id="reply_innerPopUp"
style="padding:6px 0px 0px 1px;">
<div
id="miniProfileCloseIconDiv" style="padding:6px 0px 0px
1px;">
<div style="padding:0px 0px 0px 0px;">
<span class="clickable close"
onclick="popup(''popUpDiv_reply'')"> </span>
</div>
</div>
<div style="padding:0px 0px 0px
0px;">
<div class="mainInput">
<div style="width:100%;">
<div style="width:
75%;float:left;">
<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'');"></textarea>
<br/>
<span id="remaining"
class="count">400</span>
characters remaining
<br/>
</div>
<div class="postWrap">
<%= 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>
</div>
</div>
</div>
</div>
</div>
<%end%>
***********************************************************************************************************************************
I want to know how the two javascript methods can be called from the
view.
Thanks in Advance
Regards
Chandrika
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.