1

I am customizing checkout page. I try set value in form field by using Jquery but did not work.

for making test I will try to hide all input elements in checkout page such a simple task but did not work. alert have came but input element dose not hide.

I have get some idea to why its not working from this link. I have set jquery trigger before and after set value but nothing work.

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

  $(document).ready(function(){

       $(window).load(function(){

       //$("input").trigger('keyup');
       $("input").hide();
       $("input").trigger('keyup');
       alert("hiwq");

    });
  });

});

2 Answers 2

2

It should be like below

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

  $(document).ready(function(){
   // put your code here if you want it in document.ready     
  });

$(window).load(function(){

       //$("input").trigger('keyup');
       $("input").hide();
       $("input").trigger('keyup');
       alert("hiwq");

    });

});

check jquery-what-are-differences-between-document-ready-and-window-load

4
  • thanks @Minesh Patel, I have already tried but the problem still remain. now also alert get called but the input element did not get hide. Commented Apr 19, 2016 at 13:45
  • comment out this line // $("input").trigger('keyup'); and check Commented Apr 19, 2016 at 13:48
  • thank god its finally working after setting time delay. I think the input element not get load completely that is why its not found out input element. Thanks @Minesh Patel Commented Apr 19, 2016 at 13:53
  • always welcome @BilalUsean Commented Apr 19, 2016 at 13:55
1

after setting time delay my problem got solved.I think the input element not get load completely that is why its not found out input element to hide.

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

  $(document).ready(function(){
  // put your code here if you want it in document.ready     
  });

 setTimeout(function(){

   $(window).load(function(){

   $("input").trigger('keyup');
   $("input").hide();
   //$("input").trigger('keyup');
   alert("hiwq");

   });

 }, 2000);

});
1
  • Time delay always won't work as expected. It depends on the loading speed of the page. Commented Mar 12, 2020 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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