Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to add "...." after a sentence using Ajax display tag

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
need a urgent help on Ajax.
I am using Ajax,Spring,Struts for my project.
I need help in two place :--

1. I am displaying a link which contains first 20 character of a comment and this first 20 character will end with "...." to show that this link contains more information.
After clicking on that link user can view full comment.
I want to append "...." after that 20 character using Ajax display tag.

2.I have an add comment page which will add some comment to database after clicking a save button. Maximum comment size will be 4000 character . But If I enter more then 2000 character then my form is not submiting and it is not showing any error.It simply dies there no action is performed there.

Please help in solving this problem.

Below is the code of my addComment.jsp.

<%@ include file="/common/taglibs.jsp"%>


<script language="javascript" type="text/javascript">

focusOnTextArea=function(){
document.getElementById('commentDesc').focus();

}
// --------------------------------------------------------------
// Save functions
// --------------------------------------------------------------
validateSave = function()
{
var valid = true;
var module = $F('module');
var commentDesc= $F('commentDesc');

if (module == "0")
{
alert("Please Select module.");
valid = false;
return valid;
}else {
focusOnTextArea();
}
if (commentDesc == "")
{
alert("Please Enter Comment.");
document.getElementById('commentDesc').focus();
return false;
}
if(commentDesc.length >= 4000){
alert("Comment should be less than 4000 characters.");
document.getElementById('commentDesc').focus();
valid = false;
}
return valid;
};

preSave = function()
{
var keepGoing = validateSave();
alert("Return Value===" +keepGoing);
if (keepGoing)
{
var method = $('method');
method.value='save';
var params = $('ajax');
params.value = Form.serialize('commentForm');
}
return keepGoing;
};

postSave = function()
{
var params = $('ajax');
params.value="";
};

errorSave = function()
{
alert("error");
};

// --------------------------------------------------------------
// Reset functions
// --------------------------------------------------------------
preReset = function()
{
var method = $('method');
method.value='reset';

};

postReset = function()
{

};

errorReset = function()
{
};
</script>



<div id="ajaxCommentForm">
<table class="componentContent">
<html:form styleId="commentForm" method="POST" action="/addCommentAction">

<html:hidden styleId="method" property="method"/>
<input id="ajax" type="hidden" value=""/>

<c:if test='${not empty commentForm.message}'>
<script>setTimeout("Effect.DropOut('savedMsg')", 2500);</script>
<div id="savedMsg" class="successMsg">${commentForm.message}</div>
</c:if>

<tr>
<td class="label">Module:</td>
<td>
<html:select styleId="module" name="commentForm" property="moduleId" onchange="focusOnTextArea()">
<html ption value="0">--Please Select--</html ption>
<c:forEach var="module" items="${dataList}">
<html ption value="${module.moduleId}">
<c ut value="${module.moduleName}"/>
</html ption>
</c:forEach>
</html:select>
</td>

</tr>

<tr>
<td class="label" valign="top">Comment:</td>
<td colspan="3">
<html:textarea property="commentDesc" rows="6" cols="50" />
</td>
</tr>
<tr>
<td colspan="3" align="center">
<table class="componentContent">
<tr>
<td align="right"><input id="saveButton" type="button" value="Save" class="button"/></td>
<td align="left"><input id="resetButton" type="button" value="Reset" class="button"/></td>
</tr>
</table>
</td>
</tr>
</html:form>
</table>
</div>
<ajax:htmlContent
baseUrl="addCommentAction.do"
source="resetButton"
target="ajaxCommentForm"
parameters="method={method}"
preFunction="preReset"
postFunction="postReset"
errorFunction="errorReset"/>

<ajax:htmlContent
baseUrl="addCommentAction.do"
source="saveButton"
target="ajaxCommentForm"
parameters="form={ajax},method={method},commentDesc={commentDesc}"
preFunction="preSave"
postFunction="postSave"
errorFunction="errorSave"/>

 
Marshal
Posts: 67445
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this to see why posting phrases such as:

need a urgent help on Ajax.



is likely to get your post ignored.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic