I have a single Form which allows user to create a new Gift Voucher record.
It is split into 3 input areas Voucher Details, Payment Details and Delivery Details.
I want to add a button on the Payment details section which when activated will copy some of the entered fields from the Payment section to some of the fields in the Delivery section as follows: -
I am using a Code Building product called PHP Runner which when you add a button gives you a properties widget as per attachment in which to place your bespoke code.
If you share the full HTML source with the JavaScript we may be able to suggest what you need to do, I doubt many here will be familiar with PHP Runner, I’m not.
Hi there,
I understand your point. I would have attached the product manual which I think would have been a help but as a new user I am unable to.
I have in the past had someone who unfortunately I cant contact now that was not familiar with the product at all but I would give him problems such as this one and send me back the code and which tabs on the properties window to paste it into and I was off and running. I guess I am hoping to find someone like that.
Well the most basic approach would be something like
// Add a click listener to the button confirming the payment details
document.getElementById('payment-confirm').addEventListener('click', function() {
// Get the input elements by ID
var paymentFirstName = document.getElementById('payment-first-name');
var paymentLastName = document.getElementById('payment-last-name');
var deliveryFirstName = document.getElementById('delivery-first-name');
var deliveryLastName = document.getElementById('delivery-last-name');
// Set the values of the delivery inputs to the values of the corresponding
// payment inputs
deliveryFirstName.value = paymentFirstName.value;
deliveryLastName.value = paymentLastName.value;
});
Here’s a fiddle with markup. If you have trouble applying this to your project, we can certainly give you further assistance; however even if someone would volunteer to write the entire solution for you, it would be rather tricky without seeing the markup. ;-)
Hi there,
Thank you very much for that. I certainly see where your coming from. However my HTML for the form differs from your construct and I have pasted herwith. Could not attach as I’m new user sorry.
Please note that the button I have added shows as ID New_Button and is called Copy Details
Sorry if I paste there are massive gaps and only a very small part shows. Not sure how I can it to you?
Ah well I don’t know about PHP runner either, I thought more of the generated HTML… anyway, have you tried to adapt my above snippet by adjusting the IDs?
Hi there,
Yes I have, placing the code in the Client Before Tab. When clicked there is no error, the page scrolls down a little and nothing else happens.
`// Put your code here.
// Add a click listener to the button confirming the payment details
document.getElementById(‘New_Button’).addEventListener(‘click’, function() {
// Get the input elements by ID
var PurchaseName = document.getElementById(‘PurchaseName’);
var PAddressLine1 = document.getElementById(‘PAddressLine1’);
var PAddressLine2 = document.getElementById(‘PAddressLine2’);
var PCounty = document.getElementById(‘PCounty’);
var PPostCode = document.getElementById(‘PPostCode’);
// Set the values of the delivery inputs to the values of the corresponding
// payment inputs
DeliveryName.value = PurchaseName.value;
DAddressLine1.value = PAddressLine1.value;
DAddressLine2.value = PAddressLine2.value;
DCounty.value = PCounty.value;
DPostCode.value = PPostCode.value;
});
// Uncomment the following line to prevent execution of “Server” and “Client After” events.
// return false;`