Skip to main content
ZombieLuna
Inspiring
March 4, 2021
Answered

Javascript to Make an Autofill Editable

  • March 4, 2021
  • 1 reply
  • 5623 views

I posted this somewhere else here and I didn't get the help that I needed so I'm hoping that posting it a different section might get me a bit more range.  Hope that this is okay.

I am creating a form with multi-pay options available.

I would like the first payment amount ("Amount To Be Paid on First Card") to autofill with the total amount but be editable if the total amount ("Amount To Be Paid") is to be split.  In that event, I would also like other fields ("Amount To Be Paid on Second Card") to become required if the first amount is lesser than the total amount.

I am entering the following code into the Amount To Be Paid on First Card custom calculation script field.

It pulls the auto fill, it makes the secondary payment field required, but it does not allow the amount to be changed from the autofill of the total amount.

I know that my script has conflicts.  I'm instructing it to copy information and to make fields required in the event that the amount in the second field is lesser than the amount in the above.

I'm not knowledgable enough to figure out how to instruct it to bypass the autofill if it is changed by the user; so, even if I were to type an amount into the first card's amount to be paid feild, it readjusts and autopopulates with the data from the first field.

I am still learning (mostly from this community) and would appreciate any help that can be offered.  My attempt is below.  Thank you for any assistance.

event.value = this.getField("Amount To Be Paid").value;

var n = this.getField("Amount To Be Paid On First Card").value;

if (n < "Amount To Be Paid On First Card") {
	testMyField(event.value, "Amount To Be Paid On Second Card");
}
This topic has been closed for replies.
Correct answer Nesa Nurani

Okay.  One more request.  Can you break down the code for me?  This is super complicated to my lamen eyes...  I really want to understand what I'm putting in practice.  🙂


If you choose that way you will also need custom format script for currency, instead just use this as validation script of "Amount to be paid" field:

 

this.getField("Amount To Be Paid on First Card").value = event.value;

 

That way you can set format easy, and use this as calculation script of  "Amount To Be Paid on Second Card" to set "Amount To Be Paid on Second Card" required when "Amount To Be Paid on First Card" is less then "Amount to be paid":

if(Number(this.getField("Amount To Be Paid on First Card").value) < Number(this.getField("Amount To Be Paid").value))
event.target.required = true;
else event.target.required = false;

 

 

EDIT: fixed code.

1 reply

Inspiring
March 4, 2021

Who gave you that code?

Where in your code are you making field required?

Why are you using this:

(n < "Amount To Be Paid On First Card")

What are you trying to achive with it?

ZombieLuna
Inspiring
March 4, 2021

This is me frankencodeing a bunch of stuff together.

 

Line 1 is asking it to duplicate the data in "Amount To Be Paid" in the "Amount To Be Paid On First Card" field.

 

Line 2 was the variation instruction to recognize that 'n' equals the next request.

 

The IF statement was intended to have it as if Amount To Be Paid On First Card is less then (or not equal to, but I wanted it to work before I started trying variants) Amount To Be Paid to ┐

 

Line 4 'testMyField(event.value, "Amount To Be Paid On Second Card");' and make that field required.

 

Buuuuut, like I said, I have no idea what I'm doing and it almost worked.  When I input $1000 into Amount To Be Paid, it autofilled Amount To Be Paid on First Card.  That immediately made Amount To Be Paid on Second Card required.

 

It was taunting me!  I'm sure of it.  

 

But can you help?   🙂 

Inspiring
March 5, 2021

event.value = this.getField ("Amount To Be Paid"). value;
var n = this.getField ("Amount To Be Paid On First Card"). value;

 

I propose another construction assigned to the "Amount To Be Paid" frame:
if (event.value) {// or if (event.willCommit) {
this.getField ("Amount To Be Paid On First Card"). value = event.value;
...
}
changing the value in "Amount To Be Paid" will write this value to the frame "Amount To Be Paid On First Card"

the if command ... means nothing. n (NUMBER) is greater than "Amount To Be Paid On First Card" (string, TEXT). What are you comparing here?
When you assign a value using an event, you get the same values in both frames