PDF javascript将特定值添加到其他文本框中 [英] PDF javascript adding a specific value to other text box

查看:97
本文介绍了PDF javascript将特定值添加到其他文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用PDF工作,并且已经搜索了这段代码的高低,但我正式感到难过。



我有两个文本框:当我在第一个框中输入一个值时,我需要第二个框来反映该值+5。



例如:

方框一= 3:00

方框二自动成为3:05



我的尝试:



 var firstValue = this.getField( valueOne)。 ValueAsString; 
var secondValue = this.getField(5);
if(firstValue ==3:00|| secondValue ==3:05)event.value =5;
else event.value = Number(firstValue)+ Number(secondValue);

解决方案

首先,Java和Javascript是两种不同的野兽,它是其中之一但不是两种。

据我所知,问题与PDF无关。



你是否将字段命名为5?

 var secondValue =  this  .getField(  5); 



这是不寻常的。



计算一些代码比其他任何东西都要多。

 var firstValue =   3:00; 
var secondValue = 3:05;
if (firstValue == 3: 00 || secondValue == 3:15)event.value = < span class =code-string> 5;
else event.value = Number(firstValue)+ Number(secondValue);



这种方式,我们不必猜测代码在做什么。



看起来你正在处理时间值,你不能指望转换为数字来处理正确。



而且你的编码风格很糟糕,它会以牺牲可读性为代价来输入键输入,这样更好。

< pre lang =java> var firstValue = this .getField( valueOne)。 ValueAsString;
var secondValue = this .getField( 5\" );
if (firstValue == 3: 00 || secondValue == 3:05
事件.value = 5;
else
event.value = Number(firstValue)+ Number(secondValue);





提出问题是一种技巧 [ ^ ]

在论坛中发布问题的一些指南 [ ^ ]



[更新]

引用:

因为它显然非常清楚,我不是一个专业的程序员。我不知道我在做什么 - 因此糟糕的代码并且不知道Java和JavaScript之间的区别。



我们无法猜出什么是未被告知的。 />
建议:通过一些教程正确学习语言和编程,而不是从个人项目开始。

你做的就是试图通过赢得一级方程式赛车获得驾驶执照Prix​​,它不能那样工作。

引用:

我的非法字符出现了语法错误第2行。



您是否忘记告诉我们您在问题代码中出现了相同的错误消息?

经验法则,做同样的事情在2个字段中,使用相同的语法。

尝试:

 var firstValue =  this  .getField(  Text23。 ValueAsString 的;  //  在ValueAsString之前不使用空格 
var secondValue = this .getField( Text24 .ValueAsString ; // 对同一操作使用相同的语法



Quote:

在另一个框中设置值为5会更容易吗?所以我在Text23 +其他方框中输入一个值,设置值为5 =结果出现在Text24中。



建议:解释你正在做什么的含义。

我有一个表格可以做到这一点... 
我从2个字段读取值,它们的意思是......
我做这个操作意味着...... ,结果意味着...
我将结果存储在......字段中......


Hi all,
I'm working in PDF and have searched high and low for this code but am officially stumped.

I have two text boxes: when I enter a value in the first, I need the second box to reflect that value + 5.

For example:
Box one = 3:00
Box two would automatically become 3:05

What I have tried:

​var firstValue = this.getField("valueOne"). ValueAsString;
var secondValue = this.getField("5");
if (firstValue=="3:00" || secondValue=="3:05") event.value = "5";
else event.value = Number(firstValue) + Number(secondValue);

解决方案

First of all, Java and Javascript are two different beast, it one of them but no both.
As far as I can see, the question is not related to PDF.

Did you named a field "5" ?

var secondValue = this.getField("5");


It is rather unusual.

Working out something of your code is more a guess than anything else.

​var firstValue = "3:00";
var secondValue = "3:05";
if (firstValue=="3:00" || secondValue=="3:15") event.value = "5";
else event.value = Number(firstValue) + Number(secondValue);


This way, we don't have to guess what is doing the code.

Looks like you are dealing with time values, you can't expect conversion to number to be handled correctly.

And your coding style is bad, it save 2 enter key typing at the expense of readability, this is better.

​var firstValue = this.getField("valueOne"). ValueAsString;
var secondValue = this.getField("5");
if (firstValue=="3:00" || secondValue=="3:05")
    event.value = "5";
else
    event.value = Number(firstValue) + Number(secondValue);



Asking questions is a skill[^]
Some guidelines for posting questions in the forums[^]

[Update]

Quote:

As it is apparently abundantly clear, I am not a professional coder. I have no idea what I'm doing - hence the "bad code" and not knowing the difference between Java and JavaScript.


We can't guess what is not told.
Advice: Learn language and programming properly with some tutorials, not by starting with a personal project.
What you do is like trying to get a driving license by winning a Formula 1 Grand Prix, it don't work like that.

Quote:

I got a Syntax error for an illegal character on line 2.


Did you forgot to tell us that you had the same error message in code from question?
Rule of thumb, to do the same thing on 2 fields, use the same syntax.
Try:

​var firstValue = this.getField("Text23"). ValueAsString;  // use no space before ValueAsString
var secondValue = this.getField("Text24").ValueAsString;  // use same syntax for same operation


Quote:

Would it be easier to have a set value of 5 in another box? So I input a value in Text23 + other box with set value of 5 = result appears in Text24.


Advice: explain the meaning of what you are doing.

I have a form to do this ...
I read value from 2 fields, their meaning is ...
I do this operation which mean ... , the result means ...
I store result in ... field ...


这篇关于PDF javascript将特定值添加到其他文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆