show alert using jQuery-Impromptu if elements value is empty or zero

混江龙づ霸主 提交于 2019-12-12 17:51:44

问题


I want to popup alert if elements values are empty or zero. I want to use Impromptu for that. here is example of Impromptu:

http://jsfiddle.net/hGRtH/

and my input elements are:

<select name="side_room_type" id="room_type" onchange="return getAdultRoom(this.value)" class="input-medium"><option value="0">Select Room Type</option><option value="5">Family Room</option><option value="7">Seaside Rooms</option></select>

<input type="hidden" name="side_check_in_date" onchange="return getAdultRoom(this.value)" id="side_check_in_date" value="">

<select name="side_adults" id="adults" class="input-medium"><option value="">Select Adults</option></select>

How can I use Impromptu for alerts? Thank you in advance.


回答1:


A rough assumption of what you want:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="jquery-impromptu.js"></script>
<link rel="stylesheet" media="all" type="text/css" href="jquery-impromptu.css" />
<form id="frm">
    <input type="text" name="name" id="name" />
    <input type="submit" />
</form>
<script type="text/javascript">
$(function(){
    $("#frm").on('submit', function(e){
        if($("#name").val() == ""){
            showPrompt('Please insert name', 'this is the title');
            $("#name").focus();
            e.preventDefault();   
        }
    })

    function showPrompt(msg, title){
        $.prompt(msg, {
            title: title
        });
    }
});
</script>



回答2:


  <script type="text/javascript">
$(function(){
        $("#frm").on('submit', function(e){
            if($("#name").val() == ""  || $("#name").val() == "0"){
                showPrompt();
                $("#name").focus();
                e.preventDefault();   
            }
        })

        function showPrompt(msg, title){
            var tourSubmitFunc = function(e,v,m,f){
          if(v === -1){
              $.prompt.prevState();
              return false;
          }
          else if(v === 1){
              $.prompt.nextState();
              return false;
          }
},
tourStates = [
  {
      title: 'Title',
      html: 'text of jQuery Impromptu?',
      buttons: { Done: 2 },
      focus: 1,
      position: { container: '#name', x: 30, y: 30, width: 200, arrow: 'tc' },
      submit: tourSubmitFunc
  }
];
$.prompt(tourStates);

        }
    });
      </script>

This worked for me.



来源:https://stackoverflow.com/questions/17971214/show-alert-using-jquery-impromptu-if-elements-value-is-empty-or-zero

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!