简体   繁体   中英

how to make a 2nd button to click only when first button is clicked

i have the two input type:

// First Submit Button:
<input type="submit" value="Save"/>

// Second Button:   
<input type="button" value="Go for payment" id="payment" />

i want button with the id="payment" to be function/click only when the Submit is clicked when the data is saved only . Please provide any suggestion. I am new to jquery and javascript

You can use .prop() like this:

$('#submit').click(function() {
    $('#payment').prop('disabled',false);    
});

Make sure that you're putting disabled attribute for #payment button.

<input type="button" value="Go for payment" id="payment" disabled />

Fiddle Demo

You can use jquery to enable the 2nd button after the 1st button has been clicked:

Please see below for a coded example:

//On document load
$(function(){
      //Set button disabled
      $("input[type=submit]").attr("disabled", "disabled");

      //Append a change event listener to you inputs
      $('input').change(function(){
            //Validate your form here, example:
            var validated = true;
            if($('#nome').val().length === 0) validated = false;

            //If form is validated enable form
            if(validated) $("input[type=submit]").removeAttr("disabled");                             
      });

      //Trigger change function once to check if the form is validated on page load
      $('input:first').trigger('change');
})

I hope this helps

.visable {
   visibility: hidden;
}
<input id="payment" class="visable"/>

$("input[type='submit']").on('click',function(){
$("#payment").css("visibility", "visible");

});

Just by using css.

<input type="submit" value="Submit" id="submit" />
<input type="button" value="Go for payment" id="payment" />

In script:

$('#submit').click(function() {
    $('#payment').click();    
});

I this this code will solve your problem:

<body>
<form>
<input type="submit" value="Save"/>
<input type="button" value="Go for payment" id="payment"/>
</form>
</body>

<script>
$("form").submit(function( event ) {
  $( "#payment" ).trigger( "click" );
});

$( "#payment" ).click(function() {
  alert("Hello");
});
</script>

try this Fiddle

$("#submit").click(function(){    

$("#payment").removeAttr('disabled');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM