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.
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>
<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.