Solved

Livecycle Validation - Getting a Textfield substring

Posted on 2008-09-30
1
4,002 Views
Last Modified: 2012-05-05
Hi,

Have a problem with validation using Javascript in Adobe LiveCycle Designer.

I have a textfield that I want to accept up to 12 characters, or 13 characters if preceded by a + or - symbol. I can set a maxChars on the field, but that only works for 12 or 13. I was thinking of setting the maxChars attribute with the onchange event, so if the first text char is a + or - then set maxChars to 13, otherwise set to 12. Something like

if (this.rawValue.substring(0,1) != "+" && this.rawValue.substring(0,1) != "-") {
//app.alert ("starting with + or -!");
Somehow set maxChars to 12
} else {
//app.alert ("NOT starting with + or -!");
Somehow set maxChars to 13
}

this.rawValue.substring doesn't work, despite being valid JS afaik

this.rawValue alone doesn't have the currently typed in value, only the value that was in the TextField after the last time you exited it

It might be that we have to use FormCalc etc, but I don't really want to go that route if possible.

Thanks
0
Comment
Question by:SWS001
1 Comment
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 500 total points
ID: 22607243
The onchange event is too late, i.e. it occurrs after the user leaves the text field, the onkeyup event is needed.

To get the first character in the field try:

this.value.charAt(0);

To set the maximum length try:

this.maxLength = 12;

I am not certain if it is same as Adobe LiveCycle however the following Javascript example is tested successfully in IE and FF:
<script type="text/javascript">
 
function SetMaxChars(field)
{
	var chFirst = field.value.charAt(0);
 
	if(chFirst != "+" && chFirst != "-") {
		field.maxLength = 12;
	} 
	else {
		field.maxLength = 13;
	}
}
 
</script>
 
<input type="text" onkeyup="SetMaxChars(this);" maxlength="12" />

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Free PDF Viewer for Win PC & Apple PC That Resizes Only Text 3 25
innerHTML 7 34
Sources to create infographic resume 2 17
ASP.NET Content Page 3 25
This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
Inserting page numbers in Portable Document Files not only enhances manageability but also makes them look professional. With numbered pages, the file appears more organized and it becomes easier to search for a particular page. The size and the vol…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question