I am trying to change the select item based on the value of another text box,
for example, if the value of the input (st-test) is true, the value of the select field (payment ) = Paid.
Else, the value of the select remains = Waiting for Payment.
what i did is,
jQuery(document).ready(function() {
jQuery('input[name="wpcf-st-test"]').keyup(function() {
if (jQuery(this).val() == 'true') {
I've spent quite a bit of time puzzling over this and am also having trouble getting it working.
Here's the version of the code I currently have:
document.addEventListener("DOMContentLoaded", function (event) {
(function ($) {
$("select[name^='wpcf-payment'] option[value='Waiting for Payment']").attr("selected", "selected");
$("select[name^='wpcf-payment'] option:first").removeAttr("selected");
$('input[name="wpcf-st-test"]').keyup(function (e) {
if ( $(this).val() == 'true') {
$("select[name^='wpcf-payment'] option[value='Waiting for Payment']").removeAttr("selected");
$("select[name^='wpcf-payment'] option[value='Paid']").attr("selected", "selected");
} else {
$("select[name^='wpcf-payment'] option[value='Paid']").removeAttr("selected");
$("select[name^='wpcf-payment'] option[value='Waiting for Payment']").attr("selected", "selected");
}
});
})(jQuery);
});
If you open the browser dev tools and inspect the select input markup, when you type "true" into the text field being listened to, the select dropdown correctly changes to the Paid option.
The problem is that if you keep typing, breaking the comparison, it reverts to the --Not Set-- empty option.
But the dev tools show the code is working correctly. The selected option in the browser doesn't match the option with the selected attribute (screenshot).
That doesn't make sense and I don't know why it's happening.
I also tried modifying the code to delete the --Not Set-- option rather than simply removing the selected attribute, and that also didn't work, inasmuch as the option selected in the dropdown did not correspond to the option with the selected attribute.
As I already spent quite a bit of time on this custom code, let me pass it back to you to see if you can use that to get closer to a solution.
what we are trying to do from the previous scenario is.
we have a form with the payment. we have a field called Payment status in our form. we want the status changed to be Paid once the payment is completed.
first, Once the user completes the payment. the payment page sends through a session a value 'true'.
then, we want the status in our form changed to 'Paid' in the database if the session returned true value only.
From where you are generating the session value and where exactly at what point you want to save the Payment Status.
If you can share problem URL and access details first I would like to review how you setup the things and after that I'll be able to guide you in the right direction.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Actually it will not help much as you will have to check with "WooCommerce Thawani Checkout Payment gateway" plugin author if they offer any hook that you can use to update custom field on successful/unsuccessful payment.