Problem with acrobat 9 when validating text fields
hello
i've been using script provide feedback english students. correct input turns backgroundcolor green, incorrect 1 turns red. script has been working fine many years including acrobat reader 8, version 9 gives me problem. when filling in field , pressing enter, nothing happens, when give focus filled in field again color change. leaving field turns color again original. here link example:
http://schulen.eduhi.at/herderschule/pdf/e3/e3u1sentences.pdf
try reader 9 , previous version , you'll see mean.
can me fix problem?
here code i'm using validate textfields:
//
//testletter
//
/*********** belongs to: document-level:testletter ***********/
var f = this.getfield("1")
f.value = "";
var f = this.getfield("2")
f.value = "";
function testletter(fieldname,fieldvalue)
{
var retvalue;
retvalue = false;
switch (fieldname)
{
case "1":
{
if (fieldvalue == "in australian bush.")
retvalue = true;
break;
}
case "2":
{
if (fieldvalue == "for pack of dingoes.")
retvalue = true;
break;
}
default:
{
retvalue = false;
break;
}
}
return retvalue;
}
//
//
//
//trim
//
/*********** belongs to: document-level:trim ***********/
function trim(inputstring) {
if (typeof inputstring != "string") { return inputstring; }
var retvalue = inputstring;
var ch = retvalue.substring(0, 1);
while (ch == " ") {
retvalue = retvalue.substring(1, retvalue.length);
ch = retvalue.substring(0, 1);
}
ch = retvalue.substring(retvalue.length-1, retvalue.length);
while (ch == " ") {
retvalue = retvalue.substring(0, retvalue.length-1);
ch = retvalue.substring(retvalue.length-1, retvalue.length);
}
while (retvalue.indexof(" ") != -1) {
retvalue = retvalue.substring(0, retvalue.indexof(" "))
+ retvalue.substring(retvalue.indexof(" ")+1, retvalue.length);
}
return retvalue;
}
//
//
//
//1:validate
//
/*********** belongs to: acroform:1:validate ***********/
event.value = trim(event.value);
var f = this.getfield("1"); /* field event occurs @ */
f.readonly = false;
f.fillcolor = color.ltgray
if (event.value != "")
if (testletter("1",event.value)==true)
{
f.fillcolor = color.green;
}
else
{
f.fillcolor = color.red;
}
//
//
//
//2:validate
//
/*********** belongs to: acroform:2:validate ***********/
event.value = trim(event.value);
var f = this.getfield("2"); /* field event occurs @ */
f.readonly = false;
f.fillcolor = color.ltgray
if (event.value != "")
if (testletter("2",event.value)==true)
{
f.fillcolor = color.green;
}
else
{
f.fillcolor = color.red;
}
//
//
i've been using script provide feedback english students. correct input turns backgroundcolor green, incorrect 1 turns red. script has been working fine many years including acrobat reader 8, version 9 gives me problem. when filling in field , pressing enter, nothing happens, when give focus filled in field again color change. leaving field turns color again original. here link example:
http://schulen.eduhi.at/herderschule/pdf/e3/e3u1sentences.pdf
try reader 9 , previous version , you'll see mean.
can me fix problem?
here code i'm using validate textfields:
//
//
//
/*********** belongs to: document-level:testletter ***********/
var f = this.getfield("1")
f.value = "";
var f = this.getfield("2")
f.value = "";
function testletter(fieldname,fieldvalue)
{
var retvalue;
retvalue = false;
switch (fieldname)
{
case "1":
{
if (fieldvalue == "in australian bush.")
retvalue = true;
break;
}
case "2":
{
if (fieldvalue == "for pack of dingoes.")
retvalue = true;
break;
}
default:
{
retvalue = false;
break;
}
}
return retvalue;
}
//
//
//
//
//
/*********** belongs to: document-level:trim ***********/
function trim(inputstring) {
if (typeof inputstring != "string") { return inputstring; }
var retvalue = inputstring;
var ch = retvalue.substring(0, 1);
while (ch == " ") {
retvalue = retvalue.substring(1, retvalue.length);
ch = retvalue.substring(0, 1);
}
ch = retvalue.substring(retvalue.length-1, retvalue.length);
while (ch == " ") {
retvalue = retvalue.substring(0, retvalue.length-1);
ch = retvalue.substring(retvalue.length-1, retvalue.length);
}
while (retvalue.indexof(" ") != -1) {
retvalue = retvalue.substring(0, retvalue.indexof(" "))
+ retvalue.substring(retvalue.indexof(" ")+1, retvalue.length);
}
return retvalue;
}
//
//
//
//
//
/*********** belongs to: acroform:1:validate ***********/
event.value = trim(event.value);
var f = this.getfield("1"); /* field event occurs @ */
f.readonly = false;
f.fillcolor = color.ltgray
if (event.value != "")
if (testletter("1",event.value)==true)
{
f.fillcolor = color.green;
}
else
{
f.fillcolor = color.red;
}
//
//
//
//
//
/*********** belongs to: acroform:2:validate ***********/
event.value = trim(event.value);
var f = this.getfield("2"); /* field event occurs @ */
f.readonly = false;
f.fillcolor = color.ltgray
if (event.value != "")
if (testletter("2",event.value)==true)
{
f.fillcolor = color.green;
}
else
{
f.fillcolor = color.red;
}
//
//
you have field highlighting turned on. can use javascript in file turn off user preference setting.
i'd suggest code change:
george
i'd suggest code change:
event.value = trim(event.value);
var f = event.target; /* field event occurs @ */
...
george
More discussions in Acrobat SDK
adobe
Comments
Post a Comment