javascript - Jquery popup modal, how to call from a js function -
after submit form, below line opens popup modal.
<input class="js__p_start" type="submit" value="submit" name="submit"/>
i want open popup js function check if form field not empty call popup modal, otherwise give alert fill form field.
any way call call popup using class js function.
in case need source code, see source code of http://www.hunt4flat.com
here code:
<script> $(document).ready(function(){ $("#hidden_form").submit(function(){ var mobile = $("#mobile").val(); var name = $("#name").val(); var datastring = 'mobile='+ mobile + '&name='+ name; if(name=='') { alert("please enter name"); } else { $.ajax({ type: "post", url: "ritz.php", data: datastring, cache: false, success: function(result){ alert(result); //i want call popup here, popup appear after user entereed form fields } }); } return false; }); }); </script>
how it?
js file is:
(function($) { $.fn.simplepopup = function(event) { var simplepopup = { settings: { hashtag: "#/", url: "popup", event: event || "click" }, initialize: function(link) { var popup = $(".js__popup"); var body = $(".js__p_body"); var close = $(".js__p_close"); var routepopup = simplepopup.settings.hashtag + simplepopup.settings.url; var cssclasses = link[0].classname; if (cssclasses.indexof(" ") >= 0) { cssclasses = cssclasses.split(" "); (key in cssclasses) { if (cssclasses[key].indexof("js__p_") === 0) { cssclasses = cssclasses[key] } }; } var name = cssclasses.replace("js__p_", ""); // redefine variables if there additional popap if (name !== "start") { name = name.replace("_start", "_popup"); popup = $(".js__" + name); routepopup = simplepopup.settings.hashtag + name; }; link.on(simplepopup.settings.event, function() { simplepopup.show(popup, body, routepopup); return false; }); $(window).on("load", function() { simplepopup.hash(popup, body, routepopup); }); body.on("click", function() { simplepopup.hide(popup, body); }); close.on("click", function() { simplepopup.hide(popup, body); return false; }); $(window).keyup(function(e) { if (e.keycode === 27) { simplepopup.hide(popup, body); } }); }, centering: function(popup) { var marginleft = -popup.width()/2; return popup.css("margin-left", marginleft); }, show: function(popup, body, routepopup) { simplepopup.centering(popup); body.removeclass("js__fadeout"); popup.removeclass("js__slide_top"); location.hash = routepopup; document.getelementbyid("menu_but").style.visibility = "hidden"; document.getelementbyid("totop").style.visibility = "hidden"; document.getelementbyid("cbp-spmenu-s1").style.visibility = "hidden"; }, hide: function(popup, body) { popup.addclass("js__slide_top"); body.addclass("js__fadeout"); location.hash = simplepopup.settings.hashtag; document.getelementbyid("menu_but").style.visibility = "visible"; document.getelementbyid("totop").style.visibility = "visible"; document.getelementbyid("cbp-spmenu-s1").style.visibility = "visible"; }, hash: function(popup, body, routepopup) { if (location.hash === routepopup) { simplepopup.show(popup, body, routepopup); } } }; return this.each(function() { var link = $(this); simplepopup.initialize(link); }); }; })(jquery);
using library:
$.ajax({ type: "post", url: "ritz.php", data: datastring, cache: false, success: function(result){ alert(result); //i want call popup here, popup appear after user entereed form fields var popup = new jpopup({ title: "<h2>succes</h2>", content: "<p>form has been sent succesfully, results: "+result+"</p>", buttons: [{ text: "close" }] }); popup.open(); } });
library: https://github.com/seahorsepip/jpopup
you can same jquery ui dialog jquery ui dialogs require js , aren't great in opinion :p
Comments
Post a Comment