0

I need to set a default value for the region(state) in the checkout page.

tried it using jQuery. it's showing the value the field but it's not saving.

require([ 'jquery', 'jquery/ui'], function($){

    setInterval(function () {

        if($('input[name="city"]').val() != 'Perth')
        {

           $('input[name="city"]').val("Perth");
           $('input[name="city"]').attr('readonly',true);
           $('input[name="city"]').trigger('keyup');
           $('input[name="region"]').val("WA");
           $('input[name="region"]').attr('readonly',true);
           $('input[name="region"]').trigger('keyup');

        }

        },3000);

});

https://prnt.sc/i1jvx6

when I click save it not saving the region(state)

https://prnt.sc/i1jwgf

can anyone help me? it's urgent

Thanks in advance.

3
  • In the second screenshot, it shows as Perth. Jan 17 '18 at 8:00
  • Thats the city name , region is not showing "WA" Jan 17 '18 at 8:14
  • You can set default values using CheckoutConfig in the backend. Jan 17 '18 at 8:45
0

Try to use jquery .live() function

like;

$('input[name="city"]').live('change', function() {


if($('input[name="city"]').val() != 'Perth')
        {

           $('input[name="city"]').val("Perth");
           $('input[name="city"]').attr('readonly',true);
           $('input[name="city"]').trigger('keyup');
           $('input[name="region"]').val("WA");
           $('input[name="region"]').attr('readonly',true);
           $('input[name="region"]').trigger('keyup');

        }

}
1
0
require([ 'jquery', 'jquery/ui'], function($){

    setInterval(function () {

        if($('input[name="city"]').val() != 'Perth')
        {

           $('input[name="city"]').val("Perth");
           $('input[name="city"]').attr('readonly',true);
           $('input[name="city"]').trigger('keyup');

        }

        },3000);
   setInterval(function () {
    if($('input[name="region"]').region() != 'WA')
        {

           $('input[name="region"]').val("WA");
           $('input[name="region"]').attr('readonly',true);
           $('input[name="region"]').trigger('keyup');

        }

        },3500);

});

Not sure if this will work, but try to trigger both of them separately. Or load the bigger entity first, by reversing the 3500, and 3000 values.

5
  • it's not working Jan 17 '18 at 10:04
  • Can you share if you are getting any errors in logs? Jan 17 '18 at 10:54
  • No error, in default checkout its triggering the value and saving it ..i am using Mageplaza One step checkout in that its not saving the default value Jan 17 '18 at 13:17
  • I think the extension you are using has some overridden files above default checkout so you need to check which files are loading and place your code at a proper location. This is more of an extension specific requirement Jan 17 '18 at 13:21
  • Hello @SUBINCHANDRAN , I am also using Mageplaza OSC & it's not working, You found any solution? Apr 3 '20 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.