Input buttons and <a> class buttons do not work

Asked

Viewed 77 times

0

I’m using a plugin from a modal window to make a simplified shopping cart for the customer, only the buttons select the paypal or paypal as a form of payment do not work at all. If I click the button it does not redirect to any page.

Link in the codepen with the codes: https://codepen.io/flashpremium/pen/PjwoOd/ and the result on the page: https://codepen.io/flashpremium/live/e613565ea5ed20101bdcf43dca22266b

I identified that the following line of javascript code below is making the buttons inside the modal window not work. What I do to fix?

 self.$target.on('click', function(e) { self.hide(e) });
      self.$el.on('click', function(e) { self.show(e) }); 
    },

1 answer

1


I believe whatever’s keeping your buttons from working, in fact, is e.preventDefault();.

I would suggest, since the functionality of the buttons is "disabled", that you return the functionality to them using jQuery:

$(".btn-checkout-pagseguro").click(function() {
    $("#checkOutPag").submit();
});

Giving a id to the form:

<form target="pagseguro" action="https://example.com/"
  method="post" id="checkOutPag"> <!-- adicionando esse id -->

But just commenting on the e.preventDefault(); will make your Modal work - has some other functionality in it that requires blocking of standard events?

(function($) {
	$.modal = function(el, options) {
		this.options = options;
		this.$el = $(el);
		this.$target = $(el.hash || this.$el.attr('data-target'));
		this.$backdrop = $('.modal-backdrop');

		if (this.$target.length) {
			this.$el.data("modal", this);
			this.init();
		}
	};

	$.modal.prototype = {
		init : function() {
			var self = this, settings, backdrop = $('<div/>').addClass(
					'modal-backdrop fade');

			if (!self.$backdrop.length) {
				self.$backdrop = backdrop.appendTo('body');
			}

			self.settings = settings = $
					.extend({}, self.defaults, self.options);

			self.$target.on('click', function(e) {
				self.hide(e)
			});
			self.$el.on('click', function(e) {
				self.show(e)
			});
		},

		toggle : function(e) {
			return (this.$target.hasClass('in')) ? this.hide(e) : this.show(e);
		},

		show : function(e) {
			// e.preventDefault();
			// e.stopPropagation();
			this.$target.addClass('in');
			this.$backdrop.addClass('in');
			$('body').addClass('modal-open');
		},

		hide : function(e) {
			// e.preventDefault();
			// e.stopPropagation();

			var className = e.target.className;

			if (className == 'modal-dialog' || className == 'close') {
				this.$target.removeClass('in');
				this.$backdrop.removeClass('in');
				$('body').removeClass('modal-open');
			}
		},

		defaults : {}
	};

	$.fn.modal = function(options) {
		return this.each(function() {
			new $.modal(this, options);
		});
	};

	$(document).ready(function() {
		$('[data-toggle=modal]').modal();
	});
}(jQuery));
@import url('https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900');

body {
  font-family: 'Roboto';
  color: #fff;
  background: #fff;
}

.table {
  display: table;
  width: 100%;
  height: 100%;
}

.cell {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}

.close {
  float: right;
  font-size: 21px;
  font-weight: bold;
  line-height: 1;
  color: #000000;
  text-shadow: 0 1px 0 #ffffff;
  opacity: 0.2;
  filter: alpha(opacity=20);
}

.close:hover,
.close:focus {
  color: #000000;
  text-decoration: none;
  cursor: pointer;
  opacity: 0.5;
  filter: alpha(opacity=50);
}

button.close {
  padding: 0;
  cursor: pointer;
  background: transparent;
  border: 0;
  -webkit-appearance: none;
}

.modal-open {
  overflow: hidden;
}

.modal {
  font-size: 0.875em;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  outline: none;
  height: 100%;
  width: 100%;
  z-index: 1040;
  overflow: auto;
  overflow-y: scroll;
  visibility: hidden;
  display: table;
}
.modal.in {
  visibility: visible;
}

.modal.fade .modal-dialog {
  opacity: 0;
  transform: scale(0.8) translateZ(0);
  transition: all 250ms;
}

.modal.in .modal-dialog {
  opacity: 1;
  transform: scale(1) translateZ(0);
}

.modal-dialog {
  z-index: 1050;
  display: table-cell;
  vertical-align: middle;
}

.modal-content {
  position: relative;
  background-color: #ffffff;
  
  border-radius: 3px;
  outline: none;
  background-clip: border-box;
  width: 50%;
  max-width: 450px;
  min-width: 300px;
  margin: auto;
}

.modal-backdrop {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1030;
  background-color: #000000;
  visibility: hidden;
  transition: all 250ms;
}

.modal-backdrop.fade {
  opacity: 0;
}

.modal-backdrop.in {
  opacity: 0.5;
  visibility: visible;
}

.modal-header {
  min-height: 16.428571429px;
  padding: 15px;
  border-bottom: 1px solid #e5e5e5;
}

.modal-header .close {
  margin-top: -2px;
}

.modal-title {
  margin: 0;
  line-height: 1.428571429;
}

.modal-body {
  height: 600px;
  color: #000;
  background: #fff;
  background-size: 100%;
  background-repeat: no-repeat;
  position: relative;
  border-radius: 3px;
  margin: 0 auto;
}

.md-content {
  color: #000;
  background: #fff;
  background-size: 100%;
  background-repeat: no-repeat;
  position: relative;
  border-radius: 3px;
  margin: 0 auto;
}
.md-content h3 {
  margin: 0;
  padding: 0.4em;
  text-align: center;
  font-size: 2.4em;
  font-weight: 300;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px 3px 0 0;
}
.md-content > div {
  height: 600px;
  padding: 15px 40px 30px;
  margin: 0;
  font-weight: 300;
  font-size: 1.15em;
}

h1 {
  margin-top: -120px;
  font-family: roboto;
  font-weight: 300;
}

.md-content > div p {
  margin: 0;
  margin-top: 250px;
  padding: 10px 0;
  font-size: 15px;
  font-weight: 500;
}

.entrega {
  width: 47%;
  margin-top: 15px;
  font-size: 15px;
  font-weight: 500;
  float: left;
}

.about {
  font-size: 15px;
  font-weight: 500;
  opacity: 0.70;
  text-align: center;
  display: inline-block;
  color: #313c41;
  background: #d7e3ea;
  padding: 8px;
  margin-top: 7px;
}

.md-content > div ul {
  margin: 0;
  padding: 0 0 30px 20px;
}
.md-content > div ul li {
  font-size: 14px;
  padding: 5px 0;
}
.md-content button {
  border: 2px solid #fff;
  display: block;
  margin: 0 auto;
  font-size: 0.8em;
}

.md-effect-1 .md-content {
  -webkit-transform: scale(0.7);
  -moz-transform: scale(0.7);
  -ms-transform: scale(0.7);
  transform: scale(0.7);
  opacity: 0;
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  transition: all 0.3s;
}

.md-show.md-effect-1 .md-content {
  -webkit-transform: scale(1);
  -moz-transform: scale(1);
  -ms-transform: scale(1);
  transform: scale(1);
  opacity: 1;
}

.md-effect-2 .md-content {
  -webkit-transform: translateX(20%);
  -moz-transform: translateX(20%);
  -ms-transform: translateX(20%);
  transform: translateX(20%);
  opacity: 0;
  -webkit-transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  -moz-transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
}

.md-show.md-effect-2 .md-content {
  -webkit-transform: translateX(0);
  -moz-transform: translateX(0);
  -ms-transform: translateX(0);
  transform: translateX(0);
  opacity: 1;
}

@media screen and (max-width: 32em) {
  body {
    font-size: 75%;
  }
}


.btn-checkout-pagseguro {
  background: #2cf46d;
  border: 2px solid #2cf46d;
  width: 100%;
  height: 60px;
  font-size: 15px;
  font-family: Roboto;
  font-weight: bold;
  border-radius: 5px;
  color: #fff;
  font-weight: bold;
  cursor: pointer;
  transition: 200ms;
}

.btn-checkout-pagseguro:hover {
border: 2px solid #fff;
font-size: 20px;
  background: #fff;
  color: #2cf46d;   /*#8be309;*/
}

.btn-checkout-pagseguro:active {
  -webkit-transform: scale(0.95);
   transform: scale(0.95);

}

.btn-checkout {
  background: #0b74c9;
  width: 100%;
  height: 60px;
  font-family: Roboto;
  font-weight: bold;
  font-size: 15px;
  border: 1px solid #0b74c9;
  color: #fff;
  border-radius: 5px;
  transition: 200ms;
  cursor: pointer;
}

.btn-checkout:hover {
  color: #fff;
  font-size: 20px;
  color: #0b74c9;
  border: 1px solid #fff;
  background: #fff;
}

.btn-checkout:active {
 -webkit-transform: scale(0.95);
   transform: scale(0.95);
}

input#tab-one, input#tab-two, input#tab-three {
  position: absolute;
  top: -9999px;
  left: -9999px;
}

.tab-content .tab-one-content, .tab-content .tab-two-content, .tab-content .tab-three-content {
  -webkit-transition: opacity 300ms;
  transition: opacity 300ms;
  opacity: 0;
  float: left;
  width: 100%;
  margin-right: -100%;
}

input#tab-one:checked ~ .tab-content .tab-one-content, input#tab-two:checked ~ .tab-content .tab-two-content, input#tab-three:checked ~ .tab-content .tab-three-content {
  opacity: 1;
  position: relative;
  z-index: 10;
}

input#tab-one:checked ~ .tabs label[for="tab-one"], input#tab-two:checked ~ .tabs label[for="tab-two"], input#tab-three:checked ~ .tabs label[for="tab-three"] {
  background: #b8c2c8;
  cursor:pointer;
  color: #fff;
  border-bottom-color: transparent;
  -webkit-transition: 350ms;
          transition: 350ms;
}

.tabs-holder {
  width: 100%;
  margin: 10px auto;
  background: transparent;
}

.tabs > label {
  padding: 15px;
  float: left;
  cursor:pointer;
  color: #0070cb;
  font-size: 15px;
  width: 50%;
  text-align: center;
  background: #f6f9fb;
  font-weight: bold;
    box-sizing: border-box;

}

.tabs > label:hover{
  background:#d1d0ed;
}

[for] ~ [for] {
  border-left: 0;
}

.tabs > label:last-child {
  float: right;
}

.tab-content {
  overflow: hidden;
  *zoom: 1;
  height: 140px;
  padding: 11px;
  clear: both;
  border-top: 0;
}

.nome-produto {
  width: 50%;
  background: #fff;
  color: #0070cb;
  border: 1px solid #0070cb;
  font-family: roboto;
  line-height: 40px;
  height: 40px;
  border-radius: 4px;
  margin: 0 auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="table">
   <div class="cell">
      <a href="#myModal" data-toggle="modal">Abrir Modal</a>
   </div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-body">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <div class='md-content google'>
               <p>
               <div>
                  <div class="tabs-holder">
                     <input type="radio" name="toggle" id="tab-one" checked="">
                     <input type="radio" name="toggle" id="tab-two">
                     <input type="radio" name="toggle" id="tab-three">
                     <div class="tabs">
                        <label for="tab-one" style="border-radius: 30px 0px 0px 30px;">PagSeguro</label>
                        <label for="tab-two" style="border-radius: 0px 30px 30px 0px;">PayPal</label>
                     </div>
                     <div class="tab-content">
                        <div class="tab-one-content">
                           <br>
                           <!-- PagSeguro -->
                           <form target="pagseguro" action="https://pagseguro.uol.com.br/checkout/v2/cart.html?action=add" method="post" id="test">
                              <input type="submit" value="Pague com PagSeguro" class="btn-checkout-pagseguro" src="">
                           </form>
                           <!-- ./PagSeguro -->
                        </div>
                        <div class="tab-two-content">
                           <br>
                           <!-- New PayPal Update -->
                           <form method="post" action="py/processando.php" target="_blank">
                              <input type="hidden" name="itemname" value="Conta Premium Minecraft Original"> 
                              <input type="hidden" name="itemnumber" value="10000"> 
                              <input type="hidden" name="itemdesc" value="Minecraft Original"> 
                              <input type="hidden" name="itemprice" value="29.90">
                              <input class="btn-checkout" value="Pagar com PayPal" type="submit" src="https://www.paypalobjects.com/pt_BR/BR/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - A maneira fácil e segura de enviar pagamentos online!">
                              <!-- ./New PayPal Update -->
                           </form>
                        </div>
                        <div class="tab-three-content">
                           Tab Three Content
                        </div>
                     </div>
                  </div>
               </div>
               </p>
            </div>
         </div>
      </div>
   </div>
   <!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div><!-- /.modal -->

  • Solved the problem! Thank you Daniel Gomes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.