Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Livecycle Validation - Getting a Textfield substring

Posted on 2008-09-30
1
Medium Priority
?
4,037 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 2000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this video, we show how to perform Bates Numbering/Stamping of PDF documents using Power PDF Advanced, the newest product from the Document Imaging division of Nuance Communications. There are two editions of Power PDF — Standard and Advanced. Th…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

609 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