When I select the update function, I need the pop-up interface to gather the information on the Row that you are currently on in the sheet and fill in.
Then the user can change the information to update. but not the top 3 boxes. these would only view only.
please help.
I have tried changing the Html code but not getting the information from the row, the information I enter submits correctly.
I have researched this site and others but cannot find any information on getting this to populate the popup interface box.
function inputUpdates_() {
var html = doGet();
SpreadsheetApp.getUi().showModalDialog(html, 'Update Techicians Training Dates & Comments');
}
//Create a Data Entry Form
function doGet() {
var result = HtmlService
.createTemplateFromFile('Form')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
result.setHeight(600);
result.setWidth(500)
return result;
}
//The function retrieves the data from the return form and fills the spreadsheet
function getValuesFromForm(form){
var first_name = form.first_name,
last_name = form.last_name,
student_id = form.student_id,
training_date = form.training_date,
seam_sealer = form.seam_sealer,
filler_repair = form.filler_repair,
corrosion_protection = form.corrosion_protection,
body_filler_repair = form.body_filler_repair,
plasic_repair = form.plasic_repair,
bonding = form.bonding,
sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('List')
var lastRow = sheet.getLastRow();
sheet.getRange(lastRow + 1, 1).setValue(first_name);
sheet.getRange(lastRow + 1, 2).setValue(last_name);
sheet.getRange(lastRow + 1, 3).setValue(student_id);
sheet.getRange(lastRow + 1, 4).setValue(training_date);
sheet.getRange(lastRow + 1, 5).setValue(seam_sealer);
sheet.getRange(lastRow + 1, 6).setValue(filler_repair);
sheet.getRange(lastRow + 1, 7).setValue(corrosion_protection);
sheet.getRange(lastRow + 1, 8).setValue(body_filler_repair);
sheet.getRange(lastRow + 1, 9).setValue(plasic_repair);
sheet.getRange(lastRow + 1, 10).setValue(bonding);
}
<script type="text/javascript">
function formSubmit() {
google.script.run.getValuesFromForm(document.forms[0]);
google.script.host.close();
}
</script>
<style>
input.i01 {
margin-left: 84px;
}
input.i02 {
margin-left: 85px;
}
input.i03 {
margin-left: 81px;
}
input.i04 {
margin-left: 68px;
}
input.i05 {
margin-left: 73px;
}
input.i06 {
margin-left: 79px;
}
input.i07 {
margin-left: 12px;
}
input.i08 {
margin-left: 34px;
}
input.i09 {
margin-left: 75px;
}
input.i10 {
margin-left: 112px;
}
input.i11 {
margin-left: 170px;
}
<p><font face="verdana" color="green">
</style>
<!--Login Form -->
<div id="logindiv">
<form method="POST">
<label><p><font face="verdana" color="blue">First Name: </label>
<input class="i01" type="text" name="firstName"/>
<br/>
<br/>
<label>Last Name: </label>
<input class="i02" type="text" name="last_name" /><br/>
<br/>
<label>Student Id: </label>
<input class="i03" name="student_id" list="techid" type="text" />
<datalist id="techid">
<? var data = studentid(); ?>
<? for (var i = 0; i < data.length; i++) { ?>
<option value="<?= data[i]?>"></option>
<? } ?>
</datalist>
<br/>
<br/>
<label>Training Date: </label>
<input class="i04" type="date" name="training_date" /><br/>
<br/>
<label>Seam Sealer: </label>
<input class="i05" type="date" name="seam_sealer" /><br/>
<br/>
<label>Filler Repair: </label>
<input class="i06" type="date" name="filler_repair"/><br/>
<br/>
<label>Corrosion Protection: </label>
<input class="i07" type="date" name="corrosion_protection" /><br/>
<br/>
<label>Body Filler Repair: </label>
<input class="i08" type="date" name="body_filler_repair"/><br/>
<br/>
<label>Plasic Repair: </label>
<input class="i09" type="date" name="plasic_repair"/><br/>
<br/>
<label>Bonding: </label>
<input class="i10" type="date" name="bonding" /><br/>
<br/>
<br/>
<br/>
<input class="i11" onclick="formSubmit()" type="button" value="Submit" />
<input onclick="google.script.host.close()" type="button" value="Exit" />
<br/></font></p>
</form>
Related
I have resorted to using Bootstrap popover because HTML validation exhibits the same behavior I am now experiencing. Perhaps the solution for one will work for both.
JS
var validate = validate || {};
validate.issueError = function ($elem, msg, placement) {
placement = placement == undefined ? 'bottom' : placement;
$elem.attr('data-toggle', 'popover');
$elem.attr("data-offset", "0 25%");
var exclamationPoint = "<span style='font-weight: bold; font-size:medium; color: white; background-color: orange; height: 12px; padding: 1px 6px; margin-right: 8px;'>!</span>";
var content = "<span style='font-size: smaller;'>" + msg + "</span>";
$elem.popover("destroy").popover({
html: true,
placement: placement,
content: exclamationPoint + content
})
$elem.focus();
$elem.popover('show');
setTimeout(function () { $elem.popover('hide') }, 5000);
$elem.on("keydown click", function () {
$(this).popover('hide');
$(this).off("keydown click")
})
}
validate.edits = {
required: function ($form) {
var $reqFlds = $form.contents().find('[required], [data-required]');
$reqFlds.each(function () {
var $this = $(this);
var result = ($this.filter("input, select, textarea").length) ? $this.val() : $this.text();
if (!$.trim(result)) {
validate.issueError($this, "Please fill out this field.");
return false;
}
});
return true;
}
HTML (note I have substituted "required' with "data-required" to force the Bootstrap routines).
<!DOCTYPE html>
<html>
<head>
<title>Writer's Tryst - Writers Form</title>
<link type="text/css" href="css/writers.css" rel="stylesheet" />
<style>
body {padding: 0 20px;}
.limited-offer {
background-color: white;
padding: 3px;
margin-bottom: 12px;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container-fluid">
<img id="img-writers" src="#" alt="images" />
<form id="form-writers" method="post" class="form-horizontal well">
<h1>Writers</h1>
<div class="form-group">
<label for="title" class="col-lg-3 control-label">Title</label>
<div class="col-lg-9">
<input type="text" class="form-control" data-required id="title" name="title" autofocus="true" placeholder="Title" />
</div>
</div>
<div class="form-group">
<label for="form-type" class="col-lg-3 control-label">Type of work</label>
<div class="col-lg-9">
<select class="form-control" data-required id="form-type" name="form-type"></select>
</div>
</div>
<div class="form-group">
<label for="genre" class="control-label col-lg-3">Genre</label>
<div class="col-lg-9">
<select id="genre" name="genre" class="form-control" data-required></select>
</div>
</div>
<div class="form-group">
<label for="nbr-pages" class="control-label col-lg-3">Number Pages</label>
<div class="col-lg-9">
<input type="number" id="nbr-pages" name="nbr-pages" class="form-control" data-required placeholder="Pages" />
</div>
</div>
<div id="tips">The objective of a synopsis or query letter is to entice enablers into requesting your manuscript.
It must be concise and to the point and of course very well written. One page is preferred and no more than 3 pages will be accepted.
Sample Query Letter
</div>
<p id="file-warning" class="thumbnail">Your synopsis/query letter must be a PDF file.
<a target="_blank" href="https://www.freepdfconvert.com/" target="_blank">Free file conversion to PDF.</a>
</p>
<div>
<a id="file-upload" class="btn btn-custom-primary btn-file btn-block text-xs-center" role="button">Choose PDF to Upload
<br/><div id="filename" class="btn-block" style="color: #fff">No file chosen</div>
</a>
<input type="file" id="file2upload" style="display: none">
</div><br/>
<div class="form-group">
<!-- <button type="submit" id="writers-submit" class="btn btn-custom-success btn-block m-t-8">Submit</button>-->
</div>
<div class="limited-offer">For a limited time, writer submissions will cost <span style="color: #f00; font-weight:bold">$15.00</span> to offset screening and editing costs and to promote quality synopsises and query letters. We reserve the right to change this policy without notice.</div>
<!-- <form id="form-paypal" name="form-paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" onsubmit="return ajaxSubmit()">-->
<form id="form-paypal" name="form-paypal" method="post" target="_top">
<input type="submit" class="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="U2LE82Z45PJ54">
<input style="display: block; margin: 0 auto;" id="but-pp" type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="PayPal" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
<input id="userid" name="userid" type="hidden" />
<input id="filesize-limit" name="filesize-limit" type="hidden" value="150000" />
</form>
</div>
<script>
angular.element(document).ready(function () {
showImages($("#form-writers"), $("#img-writers"), "authors", ["blake.jpg", "Melville.jpg", "lewis-carroll.jpg", "stephen-king.jpg", "twain.jpg", "camus.jpg", "nietzsche.jpg", "hesse.jpg"]);
});
$(function () {
populateWritersDropdowns();
$(document).on('change', ':file', function () {
var input = $(this),
numFiles = input.get(0).files ? input.get(0).files.length : 1,
label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
input.trigger('fileselect', [numFiles, label]);
});
$('#file-upload').on('click', function (e) {
e.preventDefault();
$('#file2upload')[0].click();
});
$("#file2upload").on("change", function () {
var filepath = $('#file2upload')[0].value;
var filename = filepath.substr(filepath.lastIndexOf("\\") + 1);
$("#filename").text(filename)
});
$("#but-pp").on("mousedown", function (e) {
//if (!$("#form-writers").get(0).checkValidity()) return false;
var $ret = validate.edits.required($("#form-writers"));
alert($ret.length);
if ($ret != true) {
$ret.focus();
return false;
}
if (!validate.edits.requireFile($("#filename"))) return false;
if (!fileEdits()) return false;
ajaxSubmit();
function fileEdits() {
var fileSizeLimit = $("#filesize-limit").val();
var file = document.getElementById('file2upload').files[0];
var fileName = file.name;
var fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
var fileSize = file.size;
if (fileSize > fileSizeLimit) {
showMessage(0, "Your file-size (" + (Math.round(parseInt(fileSize) / 1000)).toLocaleString() + "kb) exceeds the limit of " + (fileSizeLimit.toLocaleString() / 1000) + "kb");
return false;
} else {
if (fileExt.toLowerCase() != "pdf") {
showMessage(0, "Your synopsis / query letter MUST be a PDF file.");
return false;
};
return true;
}
};
function ajaxSubmit() {
var file_data = $('#file2upload').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
form_data.append('action', "upload");
form_data.append('title', $("#title").val());
form_data.append('form-type', $("#form-type").val());
form_data.append('genre', $("#genre").val());
form_data.append('nbr-pages', $("#nbr-pages").val());
form_data.append('account-id', localStorage.getItem("account-id"));
ajax('post', 'php/writers.php', form_data, success, 'Error uploading file:', 'text', false, false, false);
function success(result) {
if (result.indexOf("PDF") == -1) {
showMessage(1, "Your submission will go live and you will be notified after our reviews are complete.");
var data = {};
data['writer-id'] = result;
ajax('post', 'php/paypal-ipn.php', data, listenerStarted);
function listenerStarted(result) {
alert("pp=" + result);
}
} else {
showMessage(0, result);
}
setTimeout(function () {
document.getElementById('form-writers').reset();
$("#filename").text("No file chosen");
}, 5000);
};
};
});
});
</script>
</body>
</html>
Put together this script that will upload a file to my google drive.
I need it to be able to handle either a big .zip file, OR multiple image files.
Currently it times out if you upload a big .zip file (around 7MB)
I would prefer to have it upload multiple files.
Apps Script:
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html');
}
function uploadFiles(form) {
try {
var unitNumber = form.unitNumber;
if (unitNumber == "") {
unitNumber = "";
} else {
unitNumber = " #" + unitNumber;
}
var foldertitle = form.streetAddress + unitNumber + ' ' + form.cityName + ' ' + form.stateName + ' - ' + form.businessName + ' ' + form.managerName + ' - ' + form.propertyType;
var folder, folders = DriveApp.getFolderById("0B0V8-0eo7tx8MTQzcGFwdXF6SFU");
var createfolder = folders.createFolder(foldertitle);
folder = createfolder;
var blob = form.filename;
var file = folder.createFile(blob);
return "File uploaded successfully ";
} catch (error) {
Logger.log('err: ' + error.toString());
return error.toString();
}
}
Form Code
<body>
<div id="formcontainer">
<form id="myForm">
<div>
<input type="text" name="businessName" placeholder="Business Name">
</div>
<div>
<input type="text" name="managerName" placeholder="Manager Name">
</div>
<div>
<input type="text" name="streetAddress" placeholder="Street Address">
</div>
<div>
<input type="text" name="unitNumber" placeholder="Unit Number">
</div>
<div>
<input type="text" name="cityName" placeholder="City">
</div>
<div>
<input type="text" name="stateName" placeholder="State">
</div>
<br>
<label for="propertyType">Choose Type</label>
<br>
<select name="propertyType">
<option value="Interactive Floor Plan">IFP</option>
<option value="Pictures Only">Pictures</option>
<option value="Video Only">Video</option>
<option value="Complete Property">All</option>
</select>
<br>
<label for="myFile">Compress All Files into .zip file</label>
<br>
<input type="file" name="filename" id="myFile" multiple>
<input type="submit" value="Upload File" onclick="this.value='Uploading..';
google.script.run.withSuccessHandler(fileUploaded)
.uploadFiles(this.parentNode);
return false;">
</form>
</div>
<div id="output"></div>
<script>
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
<style>
body {
max-width: 400px;
padding: 20px;
margin: auto;
}
input {
display: inline-block;
width: 100%;
padding: 5px 0px 5px 5px;
margin-bottom: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
select {
margin: 5px 0px 15px 0px;
}
input[type="submit"] {
width: auto !important;
display: block !important;
}
input[type="file"] {
padding: 5px 0px 15px 0px !important;
}
</style>
</body>
I don't see other way to make GAS work with multiple files if not with multiple files inputs. You can add dinamically input with Jquery (or plain Javascript), and test in the server side to check how many input files got carried over.
Like so:
in HTML:
<input type="file" name="filename0" id="myFile"><div id="moreInputs"></div>
<button onClick="moreFieds()">Add more Fieds</button>
<script>
var numInputs = 1;
function moreFieds(){
$('#moreInputs').append($('<input type="file" name="filename'+numInputs+'" id="myFile">'));
numInputs++;
}
</script>
In code.gs:
var numForms = 0;
while( form[ (filename + numForms) ] ){
var blob = form[ (filename + numForms) ];
var file = folder.createFile(blob);
numForms++;
}
Or as I like more, send files inputs one by one in the script, giving each input it's own form, that way you can know when each file has done loading with the successHandler.
How can I bring three drop down menus in one line. I want to bring my day, month and year in one line but coudln't do so. Any help would be appreciable. I am attaching my jsfiddle.
<form action=
"https://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8"
method="post">
<input name="orgid" type="hidden" value="">
<input name="retURL" type="hidden" value="">
....
</form>
just add #day, #month, #birthyear{ display:inline-block;}
DEMO
Adding empty <label> tags should do the trick. FIDDLE
Link is missing in your question so I could not point exactly to the solution but try below code. Hope this meets your requirement.
<html>
<head>
<style>
* {
font-family: Arial;
font-size:12px;
}
.setDate {
position:relative;
padding:20px;
}
.dateContainer {
width:400px;
display:none;
position:absolute;
top:40px;
left:20px;
background: #ffffff;
border: 1px solid #ccc;
padding:10px;
}
.dateContainer .form-field {
display:inline-block;
margin-top: 10px;
}
</style>
<script>
$('#finalDate').focus(function () {
var id = $(this).attr('id'),
cVal = $(this).val(),
cY = cVal.substr(6, 4),
cM = cVal.substr(0, 2),
cD = cVal.substr(3, 2),
d = new Date(),
y = d.getFullYear() + 1;
setYears(1900, y);
$('#ChangeDate').clone().insertAfter($(this));
$(this).siblings('.dateContainer').find('#sYear').val(cY);
$(this).siblings('.dateContainer').find('#sMonth').val(cM);
$(this).siblings('.dateContainer').find('#sDay').val(cD);
$(this).siblings('.dateContainer').show();
setDate(id);
});
var setDate = function (id) {
$('.SetDate').click(function () {
var y = $('#sYear option:selected').val(),
m = $('#sMonth option:selected').val(),
d = $('#sDay option:selected').val(),
date = m + '/' + d + '/' + y;
$('#' + id).val(date);
$(this).parents('.dateContainer').remove();
});
$('.CancelDate').click(function () {
//$('#' + id).val(date);
$(this).parents('.dateContainer').remove();
});
}
var setYears = function (sRange, eRange) {
for (var i = sRange; i < eRange; i++) {
$('#sYear').append('<option value"' + i + '">' + i + '</option>');
};
for (var i = 1; i <= 31; i++) {
$('#sDay').append('<option value"' + i + '">' + i + '</option>');
};
}
</script>
</head>
<body>
<div class="setDate">
<label for="StartDate">Date:</label>
<input class="form-control col-lg-5" name="StartDate" type="text" id="finalDate" value="12/31/2013" />
</div>
<div id='ChangeDate' class="dateContainer">
<div class="form-field col-lg-5">
<label for="sYear">Year:</label>
<select class="form-control" id="sYear" name="sYear" style="width:100px"></select>
</div>
<div class="form-field col-lg-5">
<label for="sMonth">Month:</label>
<select class="form-control" id="sMonth" name="sMonth">
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
</div>
<div class="form-field col-lg-2">
<label for="sDay">Day:</label>
<select id="sDay" name="sDay" class="form-control"></select>
</div>
<div class="form-field col-lg-12 text-right">
Cancel
Set Date
</div>
</div>
</body>
</html>
I have the following code, but it doesn't work, can anyone help me out
<form id="myform" action="#">
<h3>Registration Form</h3>
<div id="inputs">
<!-- username -->
<label for="username">Username</label>
<input id="username" title="Must be at least 8 characters."/>
<br />
<!-- password -->
<label for="password">Password</label>
<input id="password" type="password" title="Make it hard to guess." />
<br />
<!-- email -->
<label for="email">Email</label>
<input id="email" title="We won't send you any marketing material." />
<br />
<!-- message -->
<label for="body">Message</label>
<textarea id="body" title="What's on your mind?"></textarea>
<br />
<!-- message -->
<label for="where">Select one</label>
<select id="where" title="Select one of these options">
<option>-- first option --</option>
<option>-- second option --</option>
<option>-- third option --</option>
</select>
<br />
</div>
<!-- email -->
<label>
I accept the terms and conditions
<input type="checkbox" id="check" title="Required to proceed" />
</label>
<p>
<button type="button" title="This button won't do anything">
Proceed
</button>
</p>
</form>
title attribute does the work.
Your code works in chrome, FF and IE 9 and 10
Why not use placeholder instead of title.
Supported overview
In other browsers you can use this javascript:
<script>
var doc = document;
var inputs = doc.getElementsByTagName('input'),
var supportPlaceholder = 'placeholder' in doc.createElement('input');
var placeholder = function(input) {
var text = input.getAttribute('placeholder');
var defaultValue = input.defaultValue;
input.value = text;
input.onfocus = function() {
if (input.value === defaultValue || input.value === text) {
this.value = '';
}
}
input.onblur = function() {
if (input.value === '') {
this.value = text;
}
}
};
if (!supportPlaceholder) {
for (var i = 0, len = inputs.length; i < len; i++) {
var input = inputs[i], text = input.getAttribute('placeholder');
if (input.type === 'text' && text) {
placeholder(input);
}
}
}
</script>
insert title="" attribute, it will work for you.
Try qTip - http://craigsworks.com/projects/qtip/ and see the demo - http://jsfiddle.net/ramsunvtech/zzZBM/
I am working on the Android hybrid application using phonegap and JQuery Mobile. My application involves user registration, sign in and payment. The problem I am facing is that when I try to navigate from one page to another I get message error loading page.
I am creating data-role pages and using changepage method to navigate to different page.
Here are the data-role pages and js file where I am getting this error.
First js File bookingSearchResult.js:
var jsonData=new Array();
$(document).ready(function(e) {
$(".radioCheck").live("change",(function(event, ui){
var value=$(this).val();
value=value.split("_");
var str=value[0]+ "(INR"+value[1]+"/-)";
var tempid=this.id;
tempid=tempid.split("_");
$("#spRoomType_"+tempid[2]).html(str);
}));
$("#bookingform").live("pagebeforeshow",function(e){
loadpagedata();
});
$("#btnFormSubmit").live("click",function(){
$.blockUI({ message: '<div class="loading-text">Please wait...</div>' });
var roomsData=$('#selectmenu2').val();
var aduldetails=$('#selectmenu3').val();
for(var i=1;i<=roomsData;i++){
for(var j=1;j<=aduldetails;j++){
var fname=$('#Fname_'+i+'_'+j+'').val();
var lname=$('#Lname_'+i+'_'+j+'').val();
var email=$('#Email_'+i+'_'+j+'').val();
var mobile=$('#Monumber_'+i+'_'+j+'').val();
if(fname=="")
{
$.unblockUI();
jAlert('Please enter First Name','Alert',function(){
$(".valFname").focus();
});
return false;
}
else if(!fname.match(/^[A-Za-z]+$/))
{
$.unblockUI();
jAlert('First Name can have alphabets only','Alert',function(){
$(".valFname").focus();
});
return false;
}
else if(fname.length>15)
{
$.unblockUI();
jAlert('First Name cannot be greater than 15 alphabets','Alert',function(){
$(".valFname").focus();
});
return false;
}
if(lname=="")
{
$.unblockUI();
jAlert('Please enter Last Name','Alert',function(){
$(".valLname").focus();
});
return false;
}
else if(!lname.match(/^[A-Za-z]+$/))
{
$.unblockUI();
jAlert('Last Name can have alphabets only','Alert',function(){
$(".valLname").focus();
});
return false;
}
else if(lname.length>15)
{
$.unblockUI();
jAlert('Last Name cannot be greater than 15 alphabets','Alert',function(){
$(".valLname").focus();
});
return false;
}
if(email=="")
{
$.unblockUI();
jAlert('Please enter Email Address','Alert',function(){
$(".valEmail").focus();
});
return false;
}
else if(!email.match(/^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/))
{
$.unblockUI();
jAlert('Enter valid Email Address','Alert',function(){
$(".valEmail").focus();
});
return false;
}
if(mobile=="")
{
$.unblockUI();
jAlert('Please enter Mobile Number','Alert',function(){
$('.valMobile').focus();
});
return false;
}
else if(!mobile.match(/([0-9]{10})$/))
{
$.unblockUI();
jAlert('Enter valid 10-digit Mobile Number','Alert',function(){
$('.Monumber').focus();
});
return false;
}
}
}
$.unblockUI();
$.mobile.changePage("#bookingConf");
});
});
$('#bookingSearchResult').live('pagebeforeshow',function(event){
$('#hotelListDiv').empty();
$('#hotelList').empty();
$('#detailsDiv').empty();
$('#hDisplay').text("Hotels Available in "+$('#Cityname option:selected').text());
var dayWise='';
var priceBreakup='';
var dataRetrieved=new Array();
var dynHotels="";
dataRetrieved=JSON.parse(localStorage['search']);
$.each(dataRetrieved, function (index, status) {
var cinDate=JSON.parse(localStorage['search'])[index].checkInDate;
var checkinDate=displayDate2(cinDate);
$('#topDate').text(checkinDate[0]);
var nights=$('#nights').val();
var rooms=new Array();
var pax=new Array();
var roomDetails='';
var numAdults=new Array();
numAdults[0]=$('#selectmenu3').val();
if($('#selectmenu2').val()>1){
for(var i=1;i<$('#selectmenu2').val();i++){
numAdults[i]=$("#"+"selectmenu3"+i).val();
}
}
for(var i=0;i<$('#selectmenu2').val();i++)
{
roomDetails="<br>"+roomDetails+"Room "+(i+1)+": "+numAdults[i]+" Adult</br>";
}
$.each(this.availabilityList, function (index, status) {
var dynRates='';
var hotel=this.hotelName;
var hotelId=this.hotelId;
var priceString="";
$.each(this.rate, function (index, status) {
var offerPrice=this.price;
var rateId=this.rateId;
var rateDesc=this.rateIdTypeDesc;
var roomVisited=0;
var daySplit='';
var dayWisePrice='';
$.each(this.roomGrid.room, function (index, status) {
if(roomVisited !=this.roomNumber ){
var roomNo=this.roomNumber;
var roomType=this.roomType;
var numOfPax=this.numOfPax;
$.each(this.daywiseRates, function (index, status) {
var dateVisited=0;
$.each(this.forday, function (index, status) {
if(dateVisited !=this.date ){
var day=this.date;
var dayWiseTotal=this.price;
dayWisePrice=dayWisePrice+roomNo+"%"+numOfPax+"_"+day+":"+dayWiseTotal+"#";
dateVisited=this.date;
}
});
});
}
roomVisited=this.roomNumber;
});
var buttonId="btnBooknow_"+hotelId+"_"+rateId;
var priceBreakupId="priceBreakupText$"+hotelId+"$"+rateId+"$"+dayWisePrice;
dynRates=dynRates+'<li class="pricebreakup"><div class="pricebreakup-strip">'+rateDesc+' ₹ '+offerPrice+'/-<br><span>(Lux. Tax Excl.)</span></div> <span class="priceBreak" id='+priceBreakupId+'>Price Breakup</span> <div class="submit-btn-wrap"><input name="Booknow" type="button" class="button-bg" id='+buttonId+' value="BOOK NOW"/></div></li>';
});//end of rate
dynHotels=dynHotels+'<div class="booking_search_result_hotel_item_wrap"><a id="info_popup" href="#info_popup" data-rel="dialog" class="info_btn"><img src="images/i_ico.png" width="18" height="18" alt="Info"></a><div data-role="collapsible" id="hotelList" data-collapsed="true"><h3 id="hName">'+hotel+'</h3><ul class="form-list-item booking_search_result"><li class="booking_terms">Service tax # 7.42% will be charged (As per new notification).</li><li class="check-in-details"><a id="policy_popup" href="#policy_popup" data-rel="dialog" class="info_btn"><img src="images/p_ico.png" width="27" height="26" alt="i_ico" class="i_ico"></a> Check in: '+checkinDate[1]+', '+nights+' Nights</span><br>'+roomDetails+'</li>'+dynRates+'</ul></div></div> ';
});//end of availabilityList
});
$(dynHotels).appendTo('#hotelListDiv');
$('div[data-role=collapsible]').collapsible({refresh:true});
$('input[type=button]').button({refresh:true});
$('input[name="Booknow"]').click(function(){
var btnId=this.id.split('_');
hotelIdSelected=btnId[1];
rateIdSelected=btnId[2];
$.mobile.changePage('#bookingform');
});
$('.priceBreak').click(function(){
var id=this.id;
if(typeof(Storage)!=="undefined")
{
localStorage.priceBreakId=id;
}
$.mobile.changePage('#priceBreakup');
});
});
Second js File : bookingGuestDetails.js
$(document).ready(function(){
$("#bookingConf").live("pagebeforeshow",function(e){
loadBookingConfData();
});
$(".edit-btn1").live("click",function(){
var imgId=this.id;
imgId=imgId.split('_');
var str=imgId[1];
$("#ulBookingConf li").empty();
loadBookingConfDataForEdit();
});
$("#btnSubmitConf").live("click",function(){
$.blockUI({ message: '<div class="loading-text">Please wait...</div>' });
var conFname=$(".clsConName").val();
var conEmail=$(".clsConEmail").val();
var conMobile=$(".clsConMobile").val();
if(conFname=="")
{
$.unblockUI();
jAlert('Please enter First Name','Alert',function(){
$(".clsConName").focus();
});
return false;
}
else if(!conFname.match(/^[a-zA-Z ]*$/))
{
$.unblockUI();
jAlert('First Name can have alphabets only','Alert',function(){
$(".clsConName").focus();
});
return false;
}
else if(conFname.length>15)
{
$.unblockUI();
jAlert('First Name cannot be greater than 15 alphabets','Alert',function(){
$(".clsConName").focus();
});
return false;
}
if(conEmail=="")
{
$.unblockUI();
jAlert('Please enter Email Address','Alert',function(){
$(".clsConEmail").focus();
});
return false;
}
else if(!conEmail.match(/^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/))
{
$.unblockUI();
jAlert('Enter valid Email Address','Alert',function(){
$(".clsConEmail").focus();
});
return false;
}
if(conMobile=="")
{
$.unblockUI();
jAlert('Please enter Mobile Number','Alert',function(){
$('.clsConMobile').focus();
});
return false;
}
else if(!conMobile.match(/([0-9]{10})$/))
{
$.unblockUI();
jAlert('Enter valid 10-digit Mobile Number','Alert',function(){
$('.clsConMobile').focus();
});
return false;
}
$.unblockUI();
createProvisional();
});
});
function loadBookingConfData(){
var noOfRoom=$('#selectmenu2').val();
var nights=$('#nights').val();
var noOfAdults=0;
var cinDate=JSON.parse(localStorage['search'])[0].checkInDate;
var displayDate=displayDate2(cinDate)[1];
var roomDetails='<li class="booking_full_guest_head"><ul id="booking_full_guest_head_ul"><li>Hotel <span id="hotelConf">'+localStorage.hotelNameGuestDetails+'</span></li><li>Check-in <span id="CheckinConf">'+displayDate+'</span></li><li>Nights <span id="NightsConf">'+nights+'</span></li></ul></li>';
for(var i=1;i<=noOfRoom;i++)
{
roomDetails+='<li><div class="booking_full_guest_head_edit">Room-'+i+'<br>'+$("#spRoomType_"+i).html()+'<img class="edit-btn1" id="imgEdit_'+i+'" src="images/edit-ico.jpg" width="19" height="18" alt="Edit"></div></li> ';
if(i!=1){
noOfAdults=$('#selectmenu3'+(i-1)).val();
}
else
{
noOfAdults=$('#selectmenu3').val();
}
for(var j=1;j<=noOfAdults;j++){
if(document.getElementById('Gender_'+i+'_'+j+'_0').checked)
{
roomDetails+='<li class="bookinsg_full_guest_adult_seprator"><div class="booking_full_guest_type_head"> Adult '+j+'</div><div data-role="fieldcontain"> <label for="textinput">Name </label> <input class="enFields_'+ i +'" disabled="disabled" name="textinput" type="text" id="Fname1_'+i+'_'+j+'" value="'+$("#Fname_"+i+"_"+j).val()+' '+$("#Lname_"+i+"_"+j).val()+'" /></div><div data-role="fieldcontain" class="radio-input-wrap"><fieldset data-role="controlgroup" data-type="horizontal"><label class="gender-label">Gender<span class="mandatory-gender-sign">*</span></label><input class="enFields_'+ i +'" disabled="disabled" name="Gender1_'+i+'_'+j+'" type="radio" id="Gender1_'+i+'_'+j+'_0" value="" checked /><label for="Gender1_'+i+'_'+j+'_0">Male</label><input class="enFields_'+ i +'" disabled="disabled" type="radio" name="Gender1_'+i+'_'+j+'" id="Gender1_'+i+'_'+j+'_1" value="" /> <label for="Gender1_'+i+'_'+j+'_1">Female</label></fieldset></div><div data-role="fieldcontain"><label for="textinput">Email </label><input class="enFields_'+ i +'" name="textinput" disabled="disabled" type="email" id="Email1_'+i+'_'+j+'" value="'+$("#Email_"+i+"_"+j).val()+'" /></div> <div data-role="fieldcontain"><label for="textinput">Number </label><input class="enFields_'+ i +'" name="textinput" type="number" id="Monumber1_'+i+'_'+j+'" disabled="disabled" value="'+$("#Monumber_"+i+"_"+j).val()+'" /> </div></li>';
}
else if(document.getElementById('Gender_'+i+'_'+j+'_1').checked)
{
roomDetails+='<li class="bookinsg_full_guest_adult_seprator"><div class="booking_full_guest_type_head"> Adult '+j+'</div><div data-role="fieldcontain"> <label for="textinput">Name </label> <input class="enFields_'+ i +'" disabled="disabled" name="textinput" type="text" id="Fname1_'+i+'_'+j+'" value="'+$("#Fname_"+i+"_"+j).val()+' '+$("#Lname_"+i+"_"+j).val()+'" /></div><div data-role="fieldcontain" class="radio-input-wrap"><fieldset data-role="controlgroup" data-type="horizontal"><label class="gender-label">Gender<span class="mandatory-gender-sign">*</span></label><input class="enFields_'+ i +'" disabled="disabled" name="Gender1_'+i+'_'+j+'" type="radio" id="Gender1_'+i+'_'+j+'_0" value="" /><label for="Gender1_'+i+'_'+j+'_0">Male</label><input class="enFields_'+ i +'" disabled="disabled" type="radio" name="Gender1_'+i+'_'+j+'" id="Gender1_'+i+'_'+j+'_1" value="" checked/> <label for="Gender1_'+i+'_'+j+'_1">Female</label></fieldset></div><div data-role="fieldcontain"><label for="textinput">Email </label><input class="enFields_'+ i +'" name="textinput" type="email" id="Email1_'+i+'_'+j+'" value="'+$("#Email_"+i+"_"+j).val()+'" disabled="disabled"/></div> <div data-role="fieldcontain"><label for="textinput">Number </label><input class="enFields_'+ i +'" name="textinput" type="number" id="Monumber1_'+i+'_'+j+'" disabled="disabled" value="'+$("#Monumber_"+i+"_"+j).val()+'" /> </div></li>';
}
}
}
var netCost="";
netCost=calcTotalResevationCost();
roomDetails+='<li class="booking_full_guest_adult_seprator booking_full_guest_adult_total">Total Cost INR '+ netCost +' /-</li><li class="submit-btn-wrap"><input name="Submit" type="submit" class="button-bg" id="btnCreateProv" value="Save"/><br><input name="Reset" type="reset" value="Cancel" class="button-bg"/></li>';
$("#ulBookingConf").empty();
$(roomDetails).appendTo("#ulBookingConf").trigger("create");
}
function loadBookingConfDataForEdit(){
var cinDate=JSON.parse(localStorage['search'])[0].checkInDate;
var displayDate=displayDate2(cinDate)[1];
var nights=$('#nights').val();
var noOfRoom=$('#selectmenu2').val();
var noOfAdults=0;
var roomDetails='<li class="booking_full_guest_head"><ul id="booking_full_guest_head_ul"><li>Hotel <span id="hotelConf">'+localStorage.hotelNameGuestDetails+'</span></li><li>Check-in <span id="CheckinConf">'+displayDate+'</span></li><li>Nights <span id="NightsConf">'+nights+'</span></li></ul></li>';
for(var i=1;i<=noOfRoom;i++)
{
roomDetails+='<li id="liConfPage"><div class="booking_full_guest_head_edit">Room-'+i+'<br>'+$("#spRoomType_"+i).html()+'<img class="edit-btn1" id="imgEdit_'+i+'" src="images/edit-ico.jpg" width="19" height="18" alt="Edit"></div></li> ';
if(i!=1){
noOfAdults=$('#selectmenu3'+(i-1)).val();
}
else
{
noOfAdults=$('#selectmenu3').val();
}
for(var j=1;j<=noOfAdults;j++){
if(document.getElementById('Gender_'+i+'_'+j+'_0').checked)
{
roomDetails+='<li id="liConfPageGender" class="bookinsg_full_guest_adult_seprator"><div class="booking_full_guest_type_head"> Adult '+j+'</div><div data-role="fieldcontain" id="guestDetails"> <label for="textinput">Name </label> <input class="clsConName" name="textinput" type="text" id="Fname1_'+i+'_'+j+'" value="'+$("#Fname_"+i+"_"+j).val()+' '+$("#Lname_"+i+"_"+j).val()+'" /></div><div data-role="fieldcontain" class="radio-input-wrap"><fieldset data-role="controlgroup" data-type="horizontal"><label class="gender-label">Gender<span class="mandatory-gender-sign">*</span></label><input type="radio" class="clsConRadio" name="Gender1_'+i+'_'+j+'" id="Gender1_'+i+'_'+j+'_0" value="" checked /><label for="Gender1_'+i+'_'+j+'_0">Male</label><input type="radio" class="enFields_'+ i +'" name="Gender1_'+i+'_'+j+'" id="Gender1_'+i+'_'+j+'_1" value="" /> <label for="Gender1_'+i+'_'+j+'_1">Female</label></fieldset></div><div data-role="fieldcontain"><label for="textinput">Email </label><input class="clsConEmail" name="textinput" type="text" id="Email1_'+i+'_'+j+'" value="'+$("#Email_"+i+"_"+j).val()+'" /></div> <div data-role="fieldcontain"><label for="textinput">Number </label><input type="text" class="clsConMobile" name="textinput" id="Monumber1_'+i+'_'+j+'" value="'+$("#Monumber_"+i+"_"+j).val()+'" /> </div></li>';
}
else if(document.getElementById('Gender_'+i+'_'+j+'_1').checked)
{
roomDetails+='<li class="bookinsg_full_guest_adult_seprator" id="liConfpagefulldetails"><div class="booking_full_guest_type_head"> Adult '+j+'</div><div data-role="fieldcontain"> <label for="textinput">Name </label> <input type="text" class="clsConName" name="textinput" id="Fname1_'+i+'_'+j+'" value="'+$("#Fname_"+i+"_"+j).val()+' '+$("#Lname_"+i+"_"+j).val()+'" /></div><div data-role="fieldcontain" class="radio-input-wrap"><fieldset data-role="controlgroup" data-type="horizontal"><label class="gender-label">Gender<span class="mandatory-gender-sign">*</span></label><input type="radio" class="enFields_'+ i +'" name="Gender1_'+i+'_'+j+'" id="Gender1_'+i+'_'+j+'_0" value="" /><label for="Gender1_'+i+'_'+j+'_0">Male</label><input type="radio" class="enFields_'+ i +'" name="Gender1_'+i+'_'+j+'" id="Gender1_'+i+'_'+j+'_1" value="" checked/> <label for="Gender1_'+i+'_'+j+'_1">Female</label></fieldset></div><div data-role="fieldcontain"><label for="textinput">Email </label><input type="text" class="clsConEmail" name="textinput" id="Email1_'+i+'_'+j+'" value="'+$("#Email_"+i+"_"+j).val()+'" /></div> <div data-role="fieldcontain"><label for="textinput">Number </label><input type="text" class="clsConMobile" name="textinput" id="Monumber1_'+i+'_'+j+'" value="'+$("#Monumber_"+i+"_"+j).val()+'" /> </div></li>';
}
}
}
var netCost="";
netCost=calcTotalResevationCost();
roomDetails+='<li class="booking_full_guest_adult_seprator booking_full_guest_adult_total">Total Cost INR '+ netCost +' /- </li><li class="submit-btn-wrap"><input name="Submit" type="submit" class="button-bg" id="btnSubmitConf" value="Save"/><br><input name="Reset" type="reset" value="Cancel" class="button-bg"/></li>';
$("#ulBookingConf").empty();
$(roomDetails).appendTo("#ulBookingConf").trigger("create");
}
Follows is our data-role pages for booking, one is bookingform and other is bookingConfirmationPage
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Ginger</title>
<link href="css/dark-theme.min.css" rel="stylesheet" type="text/css"/>
<!--<link href="css/jquery-ui.css" rel="stylesheet" type="text/css"/> -->
<link href="css/mystyle.css" rel="stylesheet" type="text/css"/>
<link href="css/jquery.mobile.structure-1.2.0.css" rel="stylesheet" type="text/css" />
<link href="css/jalerts.css" rel="stylesheet" type="text/css"/>
<!-- Includes Mobiscroll -->
<link href="css/mobiscroll-2.3.1.custom.min.css" rel="stylesheet" type="text/css" />
</head>
<body class="booking-bg" id="gingerAppBody">
<div data-role="page" id="booking" data-theme="a" class="form-content-wrap home-bg">
<div data-role="header" data-id="ginger_header" data-position="fixed">
<h1>BOOKING</h1>
<!------------- booking form page --------------------->
<div data-role="page" id="bookingform" data-theme="a" class="form-content-wrap">
<div data-role="header" data-id="ginger_header" data-position="fixed">
<h1>BOOKING</h1>
Back
Call
Menu
</div>
<form method="get">
<div data-role="content" class="form-content-wrap" >
<div data-role="collapsible-set" class="booking_form_wrap" id="roomListDiv"></div>
<ul class="form-list-item">
<li class="booked-by-head">
Booked By...
</li>
<li>
<div data-role="fieldcontain">
<select name="flipswitch3" id="flipswitch3" data-role="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>
<label for="flipswitch3">Booker is same as guest 1</label>
</div>
</li>
<li>
<div data-role="fieldcontain">
<input type="text" name="Fname" id="BookerFname" value="" placeholder="First Name" />
</div>
<span class="mandatory-sign">*</span>
</li>
<li>
<div data-role="fieldcontain">
<input type="text" name="Lname" id="BookerLname" value="" placeholder="Last Name" />
</div>
<span class="mandatory-sign">*</span>
</li>
<li class="radio-input-li">
<div data-role="fieldcontain" class="radio-input-wrap">
<fieldset data-role="controlgroup" data-type="horizontal">
<label class="gender-label">Gender
<span class="mandatory-gender-sign">*</span></label>
<input name="BookerGender" type="radio" id="BookerGender_0" value=""/>
<label for="BookerGender_0">Male</label>
<input type="radio" name="BookerGender" id="BookerGender_1" value="" />
<label for="BookerGender_1">Female</label>
</fieldset>
</div>
</li>
<li>
<div data-role="fieldcontain">
<input type="email" name="Email" id="BookerEmail" value="" placeholder="Email" />
</div>
<span class="mandatory-sign">*</span>
</li>
<li>
<div data-role="fieldcontain">
<input type="tel" name="Monumber" id="BookerMonumber" value="" placeholder="Mobile Number" />
</div>
<span class="mandatory-sign">*</span>
</li>
<li>
<div data-role="fieldcontain">
<select name="flipswitch2" id="flipswitch2" data-role="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>
<label for="flipswitch2">Subscribe to the 'Ginger' newsletter</label>
</div>
</li>
<li class="submit-btn-wrap">
<input name="Submit" type="submit" value="Submit" id="btnFormSubmit" class="button-bg"/>
<br>
<input name="Reset" type="reset" value="Reset" class="button-bg"/>
</li>
</ul>
</div>
</form>
</div>
<!------------- booking confirmation page --------------------->
<div data-role="page" id="bookingConf" data-theme="a" class="form-content-wrap">
<div data-role="header" data-id="ginger_header">
<h1>BOOKING</h1>
Back
Call
Menu
</div>
<form method="get">
<div data-role="content" class="form-content-wrap" >
<ul id="ulBookingConf" class="form-list-item booking_payment">
</ul>
</div>
</form>
</div>
</div>
<script src="js/head.min.js"></script>
<script>
head.js("js/jquery-1.8.2.min.js", "cordova-2.1.0.js", "js/jquery-ui.min.js", "js/jquery.blockUI-min.js","js/jquery.alerts.min.js","jquery.mobile/jquery.mobile-1.2.0.min.js","js/mobiscroll-2.3.1.custom.js","js/registration.js","js/booking.js","js/bookingSearch.js","js/bookingSearchResult.js","js/bookingGuestDetails.js","js/paymentSuccess.js","js/priceBreakup.js","js/common.js",function(){
//head.js("js/jquery-1.8.2.min.js", "cordova-2.1.0.js", "js/jquery-ui.min.js", "js/jquery.blockUI-min.js","js/jquery.alerts.min.js","jquery.mobile/jquery.mobile-1.2.0.min.js","js/mobiscroll-2.3.1.custom.js","js/default.js","js/registration1.js","js/booking1.js","js/paymentSuccess.js",function(){
localStorage.clear();
$.mobile.selectmenu.prototype.options.nativeMenu = false;
$.mobile.phonegapNavigationEnabled = true ;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.is('#booking')){
e.preventDefault();
navigator.app.exitApp();
}
else {
navigator.app.backHistory();
}
}, false);
}
});
</script>
</body>
</html>
With jquery mobile this
$(document).ready(function(){
is not needed (actually is wrong to use it like this. See here.)
When you navigate to a page, a series of events is being fired.
pagebeforecreate, pagecreate, pagebeforeshow, pageshow etc are some of
them. You bind to those events not document ready. Since you use
phonegap you should see the deviceready event and mobileinit.