-1

How do I disable the submit button once the photos is displayed on the page? Anyone knows? Here's my code:

        if("#pic" == true){
         }
         else{
           $("#submit").click(function () {           
           var button = $(this);
           button.attr('disabled', 'disabled');           
          });

        }
Rod
  • 61
  • 1
  • 10
  • https://stackoverflow.com/questions/15122526/disable-button-in-jquery – JP4 Nov 27 '18 at 00:36
  • the submit button need to disabled when the photo is displayed – Rod Nov 27 '18 at 00:37
  • 1
    Do you have some sort of variable keeping track of whether the photo is displayed or not? – JP4 Nov 27 '18 at 00:39
  • Just to let you know you're missing a closing bracket for the first if statement. if("#pic" == true){ //if block }else{ //else block } – Sarah Nov 27 '18 at 00:42
  • Possible duplicate of [Disable button in jQuery](https://stackoverflow.com/questions/15122526/disable-button-in-jquery) – Rob Nov 27 '18 at 00:46

1 Answers1

0

here's the modified code

$('#pic').on('load', function() {
  console.log("loaded");
  
  $('#submit').attr('disabled',true);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img id="pic" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" />

<button id="submit">hello</button>

if the img source is improper it won't render and the load method is hence not called, so we are sure of the proper image source and after rendering it calls the Load method in which you can disable your button

Yash Soni
  • 764
  • 3
  • 14