vinzi vinzi - 5 months ago 8
Javascript Question

how to make 2 condition in button clicked jquery

hello is that possible to make a two condition from 1 button clicked?

if(unable == 4) {
$("#formitem").submit(function () {
$("#order_4").appendTo("body");
var message = "<?=$message_change_location?>";
var resotid = <?=$restaurant_info["restaurant_id"]?>;
var restoname = "<?=$restaurant_info["restaurant_name"]?>";
var restomenu = "<?=$restaurant_menu?>";
var postal = "<?=$postal?>";
var delivery_no = "<?=$delivery_no?>"
jQuery.ajax({
type: "GET",
url: "/ajax/order_unable",
dataType: 'html',
data: {
message_change_location: message,
restid: resotid,
restname: restoname,
restmenu: restomenu,
postal: postal,
delivery_no: delivery_no,
},
success: function (res) {
$("#order_4_show").html(res);
$("#order_4").modal("show");
}

});
return false;
});
}else if($("#second_notif") == "show"){
$("#formitem").submit(function () {
alert("asdf");
});


i want to make a condition if
second_notif
is showed, than if i click
$("#formitem")
for the second times will show the alert. The first click will show pop up windows, and there is not any problem here,

in the pop up windows there is a script to show the
second_notif
, with this following code :

<script>
$(document).ready(function() {
$("#change_location_2").click(function () {
$(".vendor-heading").hide();
$(".location-header").hide();
$("#order_4").modal("hide");
$("#second_notif").show();
return true;
});
});

</script>


and there in same page on where to show the pop up windows there is a code to show the
second_notif
too :

$("#change_location").click(function(){
$(".vendor-heading").hide();
$(".location-header").hide();
$("#second_notif").show();
return true;
});


here is the view for the
second_notif
:

<div id="second_notif" style="display:none;">
<?php $this->load->view('MAIN/'.country_code.'/search');?>
</div>


i can show the pop up windows, and show the
second_notif
when i clicked
formitem
button, but when the
second_notif
has beeb showed, why if i clicked the same button again, why i cant show the alert?
guys can you help me how to show the alert?

p.s alert is not my goal, i will change the alert to other view
please help me guys, thank you (:

Answer

First of all, you only need one event handler for this method. You can then move your conditionals into the handler.

Secondly, your condition $('#second-notif') == 'show' will not work, as is will never evaluate to true. To test if an element is visible using jQuery, use the .is(':visible') method. Here's a quick example of what you're looking for:

JSFiddle

Comments