How to send Geolocation from google form? - javascript

Please I need your help here anyone. I was building a google form and I needed to add Geocode to the form so that users can send their location with the filled form. So I got this piece of code from Maxi Research (link). I did everything right but when it got to the point the user has to click the geolocation webapp link to send location coordinates I receive the error ("Exception: No HTML file named Index was found. (line 2, file "Code")"
I need help to recognize what's wrong in the code. Thanks
function doGet() {
return HtmlService.createHtmlOutputFromFile('Index');
}
function getLoc(value) {
var destId = FormApp.getActiveForm().getDestinationId() ;
var ss = SpreadsheetApp.openById(destId) ;
var respSheet = ss.getSheets()[0] ;
var data = respSheet.getDataRange().getValues() ;
var headers = data[0] ;
var numColumns = headers.length ;
var numResponses = data.length;
var c=value[0];
var d=value[1];
var e=c + "," + d ;
// the script will add device geocode data in last submit data row by clicking the link on confirmation page that shows up after hitting the submit button
// geocode data here consists of 3 columns : time to click the link, longitude & latitude and address (using reverse geocode)
// as long as clicking the link is done before next respondent submit button, data will be entered in the right row.
// however particularly for the case of multiple devices that submit data at about the same time then whichever device clicks the link closer to the last submit row timestamp, their geodata will be entered in the last submit data row.
// leaving geocode column in the row above empty. In this case the geocode data will be in red font
// If sometime later another device click the link then the geodata will be entered in closest missing geodata row. The data will also be in red font
// Therefore for red font data you may want to check manually after completion for correct geodata entry. In the questionnaire add question about address to help checking.
if (respSheet.getRange(1,numColumns).getValue()=="GeoAddress") {
//fill data for second respondents onwards no missing geo data
// time here is Jakarta, you may need to change time to your local time (in GMT)
if (respSheet.getRange(numResponses,numColumns-2).getValue()=="" && respSheet.getRange(numResponses-1,numColumns-2).getValue()!="" ){
respSheet.getRange(numResponses,numColumns-2).setValue(Utilities.formatDate(new Date(), "GMT+7", "MM/dd/yyyy HH:mm:ss"));
respSheet.getRange(numResponses,numColumns-1).setValue(e);
var response = Maps.newGeocoder().reverseGeocode(value[0], value[1]);
f= response.results[0].formatted_address;
respSheet.getRange(numResponses,numColumns).setValue(f);
}
//fill data with previous geo data missing. red font
else if (respSheet.getRange(numResponses,numColumns-2).getValue()=="" && respSheet.getRange(numResponses-1,numColumns-2).getValue()=="" ){
respSheet.getRange(numResponses,numColumns-2).setValue(Utilities.formatDate(new Date(), "GMT+7", "MM/dd/yyyy HH:mm:ss")).setFontColor("red");
respSheet.getRange(numResponses,numColumns-1).setValue(e).setFontColor("red");
var response = Maps.newGeocoder().reverseGeocode(value[0], value[1]);
f= response.results[0].formatted_address;
respSheet.getRange(numResponses,numColumns).setValue(f).setFontColor("red");
}
//to fill missing previous data. red font
else if (respSheet.getRange(numResponses,numColumns-2).getValue()!=""){
for (i = 0; i < numResponses; i++) {
if (respSheet.getRange(numResponses-i,numColumns-2).getValue()=="") {
respSheet.getRange(numResponses-i,numColumns-2).setValue(Utilities.formatDate(new Date(), "GMT+7", "MM/dd/yyyy HH:mm:ss")).setFontColor("red");
respSheet.getRange(numResponses-i,numColumns-1).setValue(e).setFontColor("red");
var response = Maps.newGeocoder().reverseGeocode(value[0], value[1]);
f= response.results[0].formatted_address;
respSheet.getRange(numResponses-i,numColumns).setValue(f).setFontColor("red");
break; }
}
}
}
else if (respSheet.getRange(1,numColumns).getValue()!="GeoAddress") {
//create labels in first row
respSheet.getRange(1,numColumns+1).setValue("GeoStamp");
respSheet.getRange(1,numColumns+2).setValue("GeoCode");
respSheet.getRange(1,numColumns+3).setValue("GeoAddress");
//fill data for first respondent
if (numResponses==2) {
respSheet.getRange(numResponses,numColumns+1).setValue(Utilities.formatDate(new Date(), "GMT+7", "MM/dd/yyyy HH:mm:ss"));
respSheet.getRange(numResponses,numColumns+2).setValue(e);
var response = Maps.newGeocoder().reverseGeocode(value[0], value[1]);
f= response.results[0].formatted_address;
respSheet.getRange(numResponses,numColumns+3).setValue(f);
}
else if (numResponses > 2){
respSheet.getRange(numResponses,numColumns+1).setValue(Utilities.formatDate(new Date(), "GMT+7", "MM/dd/yyyy HH:mm:ss")).setFontColor("red");
respSheet.getRange(numResponses,numColumns+2).setValue(e).setFontColor("red");
var response = Maps.newGeocoder().reverseGeocode(value[0], value[1]);
f= response.results[0].formatted_address;
respSheet.getRange(numResponses,numColumns+3).setValue(f).setFontColor("red");
}
}
}
<!DOCTYPE html>
<html>
<script>
(function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
})()
function showPosition(position) {
var a= position.coords.latitude;
var b= position.coords.longitude;
var c=[a,b]
getPos(c)
function getPos(value) {
google.script.run.getLoc(value);
}
}
</script>
<body>
<p> GeoCode Entered </p>
</body>
</html>

Maybe this works:
https://www.youtube.com/watch?v=J93uww0vMFY
Tutorial on Geotagging (Geo-stamp and Time-stamp) google forms. Add info on Latitude, Longitude, and Address (Street name and number, city, state, zip code, and country) of a device submitting google forms. Linking user’s location within google forms. Google forms integration with google maps.

Related

How to get email alerts when a cell value changes (based on Formula) on Google sheets?

I want a notification/email when a cell value in column 5 of the spreasheet changes to 'Buy' which is based on formula =IF(AND(B2>D2),"Buy","Skip"). Attachment Link provided below. The Sheet autorefreshes based on Googlefinance data.
I have tried the below script, but it triggers notification/Email only when I change the cell manually. I am not a code writer, but have managed to find below script and added some tweaks of my own.
Can somebody please help me in resolving this or provide an alternate solution?
Also script written on third Party apps will be appreciated.
function triggerOnEdit(e)
{
showMessageOnUpdate(e);
}
function showMessageOnUpdate(e)
{
var range = e.range;
SpreadsheetApp.getUi().alert("range updated " + range.getA1Notation());
}
function checkStatusIsBuy(e)
{
var range = e.range;
if(range.getColumn() <= 5 &&
range.getLastColumn() >=5 )
{
var edited_row = range.getRow();
var strongBuy = SpreadsheetApp.getActiveSheet().getRange(edited_row,5).getValue();
if(strongBuy == 'Buy')
{
return edited_row;
}
}
return 0;
}
function triggerOnEdit(e)
{
showMessageOnBuy(e);
}
function showMessageOnBuy(e)
{
var edited_row = checkStatusIsBuy(e);
if(edited_row > 0)
{
SpreadsheetApp.getUi().alert("Row # "+edited_row+"Buy!");
}
}
function sendEmailOnBuy(e)
{
var buy_row = checkStatusIsBuy(e);
if(buy_row <= 0)
{
return;
}
sendEmailByRow(buy_row);
}
function sendEmailByRow(row)
{
var values = SpreadsheetApp.getActiveSheet().getRange(row,1,row,5).getValues();
var row_values = values[0];
var mail = composeBuyEmail(row_values);
SpreadsheetApp.getUi().alert(" subject is "+mail.subject+"\n message "+mail.message);
}
function composeBuyEmail(row_values)
{
var stock_name = row_values[0];
var cmp = row_values[1];
var volume = row_values[2];
var message = "The Status has changed: "+stock_name+" "+cmp+
" Volume "+volume;
var subject = "Strong Buy "+stock_name+" "+cmp
return({message:message,subject:subject});
}
function triggerOnEdit(e)
{
sendEmailOnBuy(e);
}
var admin_email='sendemail#gmail.com';
function sendEmailByRow(row)
{
var values = SpreadsheetApp.getActiveSheet().getRange(row,1,row,5).getValues();
var row_values = values[0];
var mail = composeBuyEmail(row_values);
SpreadsheetApp.getUi().alert(" subject is "+mail.subject+"\n message "+mail.message);
[https://docs.google.com/spreadsheets/d/12k5DF8rvuKex77B8uRWpx1FoMmSNaMdGvhNEEbXKCFc/edit?usp=sharing][1]
Apps script triggers cannot be trigerred by non manual input as specified in the documentation:
Script executions and API requests do not cause triggers to run. For example, calling Range.setValue() to edit a cell does not cause the spreadsheet's onEdit trigger to run.
What you can do instead is to set up a time-based trigger that scans your column 5 at regular interval and sends you an email if a cell contains 'Buy':
function sendEmailOnUpdate() {
var range = SpreadsheetApp.getActive().getRange('E2:E').getValues();
for (i = 0; i < range.length; i++) {
var cell = range[i];
if (cell == 'Buy') {
// Send email using Gmail
}
}
}
To set the trigger, head to Triggers and select time-based:
If you don't want to receive more emails for a cell you receive an alert for, make sure to make apps script change its value once the email has been sent.

Script google sheets form autocomplete and fill cell

I have a form with an input type "text" which has an autofill function from a list that is fed from a spreadsheet in google drive (this works fine); by selecting the desired option from the list; I want another field in the form to be filled automatically with the cell next to the right, that is, if I select the data (character string) of cell I5 with the auto-complete option, the new text field should be filled automatically with the contents of cell J5 (this does not work). The event I use does not capture the entire string of cell I5, but only the typed characters, can anyone help me?
I have this code:
//page-js.html
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("redIps").addEventListener("blur",getRegimenIps);
google.script.run.withSuccessHandler(populateRed).getRed();
});
//page-js.html
function getRegimenIps(){
var redIpsStr = document.getElementById("redIps").value;//****not capture the entire string***
google.script.run.withSuccessHandler(updateIpsReg).getIpsReg(redIpsStr);
}
//page-js.html
function updateIpsReg(regimen){
document.getElementById("redIpsReg").value = regimen;
M.updateTextFields();
}
//funcs.gs
function getRed(){ //****This works fine ****
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("listas");
var data = ws.getRange(1,9).getDataRegion().getValues();
var options = {};
data.forEach(function(v){
options[v[0]]=null;
});
return options
}
//funcs.gs
function getIpsReg(redIpsStr){ //****This does not work****
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("listas");
var data = ws.getRange(1,9,ws.getLastRow(),2).getValues();
var redIpsList = data.map(function(r){ return r[0]; });
var regList = data.map(function(r){ return r[1]; });
console.log(redIpsStr);
var position = redIpsList.indexOf(redIpsStr);
if (position > -1){
return regList[position].toFixed(2);
}else{
return 'Unavailable';
}
}//end getIpsReg(redIpsStr)

Ovewrite table Google Script interactive Google Sheet to Google Docs and vice-versa

This is my final project in view mode :
https://drive.google.com/open?id=1gOOb3hND3q2v0vTy8SfPVHFiCnTkJPR5
each row corresponds to a Google Doc project so when I modify in the row it will modify the corresponding Doc and when I click to see the document in the same window when I modify if then click the submit button I will change the row so I have an interactivity 100% with only the trigger onEdit(e) which will call function Edit(e) and openDialog(e).
The problem is that it can overwrite the Google Doc file as in the image. The problem comes from function
onEdit(e){
Edit(e);
openDialog(e); // tick to see the project in the same window and modify it transfer to the row
}
if I put openDialog(e); in comment if for instance I delete a text field in the row it will modify it correctly and with the openDialog(e) it will overwrite it. I've tried to put the openDialog code into the Edit(e) code as in the New.gs file but it's unsuccesful and close the doc https://script.google.com/d/1bV_eJONvUAbHyO6OB04atfm_sb5ZO8LWNoQ23fxf0lFnRzHRSwW7hsQc/edit?usp=sharing Do you have an idea to solve it? Thank you very much :) Separately they function very well. Together no it can overwrte the file so I don't know I need to close the Google Doc at very time because I open it 2 times?
It's the column J; I set a trigger to view the Google Doc in the same window and I can modify inside submit button and will change the row (this is the openDialog corresponding part)
Edit : sorry this is the code
var TITLE = 'Show Google Doc';
var SPREADSHEET_ID = "17ssKkCAoPUbqtT2CACamMQGyXSTkIANnK5CjbbZ1LZg"; // = assign your spreadsheet id to this variable
var column_name_project ;
var column_code_project ;
var column_chef_project;
var column_service ;
var column_other_services ;
var column_type_of_project ;
var column_perimeter ;
var column_date_project ;
var COLUMN_URL ;
var COLUMN_VIEW_Google_Doc;
/** will return the number of the column correspondant **/
function find_columns_in_projet(){
//search the columns
}
function onEdit(e){
Edit(e);
// openDialog(e);
}
function Edit(e) {
find_columns_in_projet();
var tss_bis = SpreadsheetApp.openById(SPREADSHEET_ID);
var sheet_bis = tss_bis.getSheets()[0];
var numRows_bis = sheet_bis.getLastRow();
var lastColumn_bis = sheet_bis.getLastColumn();
//from the second line car the first line we have the headers
var data_sheet = sheet_bis.getRange(1,1,numRows_bis,lastColumn_bis).getDisplayValues();
//Access the range with your parameter e.
var range = e.range;
var row = range.getRow();
var column = range.getColumn();
if( e.range.getColumnIndex() != COLUMN_URL + 1 ) {
var URL = data_sheet[row-1][COLUMN_URL-1];
Logger.log('Le URL est bien : ' , URL);
var body = DocumentApp.openByUrl(URL).getBody();
Logger.log('The body is ' + body );
if(body)
{... code to write the information from the spreadsheet to the Google Doc
}
}
}
/** every row in the current Sheet corresponds to a Google Doc Document **/
/** to see the Google Doc in the same page click in colum J and be able to modify the Google Doc 8 rows table inside
By clicking the button Submit it will transfer the information with what you have changed to the row of the corresponding project int the Sheet **/
function openDialog(e) {
/** columns in the Spreadsheet that are lines in the Google Doc table **/
/** find_columns_in_projet();
/** the good Sheet **/
if( ( e.range.getSheet().getName() === "Sheet1" ) && ( e.range.getColumnIndex() == COLUMN_VIEW_Google_Doc ) ) {
if( e.value === "TRUE" ) {
try {
//Get Google Doc body
/** the URL that is in the column I **/
var URL = e.range.offset(0,-1,1,1).getValue();
e.range.setValue("FALSE");
// Add this line
var ui = HtmlService.createTemplateFromFile('ModeLessDialog');
ui.body = URL; // Pass url to template
ui.insert = e.range.getRow() ;
ui = ui.evaluate().setWidth(1000).setHeight(500);
SpreadsheetApp.getUi().showModalDialog(ui, 'Show Google Doc');
}
catch(err) {
Logger.log(err);
}
}
}
}
function submitDoc(url,insert) {
/** the Spreadsheet need for getRange insert position **/
var tss_bis = SpreadsheetApp.getActiveSpreadsheet();
var sheet_bis = tss_bis.getSheets()[0];
find_columns_in_projet();
try {
Logger.log(url);
var google_doc = DocumentApp.openByUrl(url) ;
var body = google_doc.getBody();
if(body) {
code to write the information from the Google Doc into the Spreadsheet by button submit
}
Logger.log(body);
}
return true;
}
catch(err) {
Logger.log(err);
}
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<iframe id="srcFrame" src="<?= body ?>" name="<?= insert ?>" width="1000" height="400"></iframe>
<input type="button" value="Sumit changes to the Spreadsheet" onclick="submitDoc()">
<script>
function submitDoc() {
var url = document.getElementById("srcFrame").src;
var insert = document.getElementById("srcFrame").name;
google.script.run.submitDoc(url,insert);
google.script.host.close();
}
</script>
</body>
</html>

Google Spreadsheet Script - Autosort on Table Change

Using Google Apps Script, I have the following code that automatically sorts a table whenever I edit information in the table.
function onEdit(event){
var sheet = event.source.getActiveSheet();
var columnToSortBy = 3;
var tableRange = "A3:AQ11";
var range = sheet.getRange(tableRange);
range.sort( { column : columnToSortBy, ascending: false } );
}
However, my entire table is populated by formulas that reference different sheets, and if I change a value in a different sheet, the tables values on the first sheet change, but it does not get sorted b/c the event did not occur on that sheet.
Is there a way to add functionality to sort the table whenever information in the table changes, rather than a manual edit to the table? I have looked into the onChange() event, but not sure how exactly it could be used.
onChange docs has an example:
From : https://developers.google.com/apps-script/reference/script/spreadsheet-trigger-builder
var sheet = SpreadsheetApp.getActive();
ScriptApp.newTrigger("myFunction")
.forSpreadsheet(sheet)
.onChange()
.create();
how to add triggers: From http://www.labnol.org/internet/google-docs-email-form/20884/
/* Send Google Form Data by Email v3.0 */
/* Source: http://labnol.org/?p=20884 */
/**
* #OnlyCurrentDoc
*/
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers)
ScriptApp.deleteTrigger(triggers[i]);
ScriptApp.newTrigger("SendGoogleForm")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit().create();
}
function SendGoogleForm(e) {
if (MailApp.getRemainingDailyQuota() < 1) return;
// You may replace this with another email address
var email = "hello#ctrlq.org";
// Enter your subject for Google Form email notifications
var subject = "Google Form Submitted";
var s = SpreadsheetApp.getActiveSheet();
var columns = s.getRange(1, 1, 1, s.getLastColumn()).getValues()[0];
var message = "";
// Only include form fields that are not blank
for (var keys in columns) {
var key = columns[keys];
if (e.namedValues[key] && (e.namedValues[key] !== "")) {
message += key + ' :: ' + e.namedValues[key] + "\n\n";
}
}
MailApp.sendEmail(email, subject, message);
}
/* For support, contact the develop at www.ctrlq.org */
Go to the Run menu and choose Initialize. The Google Script will now require you to authorize the script – just click the Accept button and you’re done.
Or you can use an onOpen function to auto add, I think "FormEmailer" includes and example of how.

Javascript for Zip Code validation

I'm attempting to have Javascript validate a user-entered zip code.
If it is within the list of valid zip codes, it should take them to a new page to schedule an appointment. If the zip code isn't in the listing, it should display a message that says that it isn't covered by the service area and then keep them on the page.
I have it working to where it takes them to the appointment page if it's valid, but it also takes them to the appointment page if it isn't valid.
Would you guys mind helping me figure this out?
Here is the page the Javascript is running on: http://platinumfactoryservice.com/service-area/
Below is the code:
<script type = "text/javascript">
function checkZip() {
var z = document.myform.zip;
var zv = z.value;
if (!/^\d{5}$/.test(zv)) {
alert ("Please enter a valid Zip Code");
document.myform.zip.value = "";
myfield = z; // note myfield must be a global variable
setTimeout('myfield.focus(); myfield.select();' , 10); // to fix bug in Firefox
return false;
}
var codes = [26003,26030,26031,26032,26035,26036,26037,26038,26039,26040,26041,26058,26059,26060,26062,26070,26074,26075,43713,43716,43718,43719,43747,43750,43757,43759,43768,43773,43778,43902,43905,43906,43909,43912,43913,43915,43916,43917,43927,43928,43933,43934,43935,43937,43938,43939,43940,43941,43942,43943,43947,43948,43950,43951,43952,43953,43963,43967,43971,43972,43977,43985,15004,15017,15018,15019,15021,15025,15028,15031,15034,15035,15045,15046,15047,15053,15054,15055,15056,15057,15060,15064,15071,15078,15081,15082,15088,15102,15104,15106,15108,15110,15112,15116,15120,15122,15123,15126,15127,15129,15131,15132,15133,15134,15135,15136,15137,15139,15140,15142,15143,15145,15146,15147,15148,15201,15202,15203,15204,15205,15206,15207,15208,15209,15210,15211,15212,15213,15214,15215,15216,15217,15218,15219,15220,15221,15222,15223,15224,15225,15226,15227,15228,15229,15230,15231,15232,15233,15234,15235,15236,15237,15239,15240,15241,15242,15243,15244,15250,15251,15252,15253,15254,15255,15257,15258,15259,15260,15261,15262,15264,15265,15267,15268,15270,15272,15274,15275,15276,15277,15278,15279,15281,15282,15283,15286,15289,15290,15295,15301,15312,15317,15321,15323,15339,15340,15342,15350,15361,15363,15365,15367,15376,15378,15379,15347,15330,23705,23703,23707,23708,23704,23709,23702,23701,23326,23328,23327,23322,23325,23320,23324,23323,23321,23520,23519,23541,23512,23551,23515,23529,23506,23501,23514,23521,23518,23502,23503,23505,23513,23509,23504,23508,23511,23517,23510,23507,23523,23459,23458,23450,23479,23471,23466,23467,23465,23463,23461,23451,23460,23456,23452,23455,23454,23453,23462,23464,23457,23261,23291,23260,23225,23221,23249,23222,23223,23241,23232,23224,23290,23173,23298,23273,23274,23289,23279,23282,23276,23278,23295,23219,23218,23220,23269,23286,23292,23293,23285,23284,23228,23227,23226,23229,23075,23231,23230,23294,23289,23060,23059,23075,23288,23242,23238,23250,23233,23255,23150,23058,23234,23831,23235,23237,23236,23836,23114,23112,23113,23297,23832,23120,23838,23801,23803,23804,23805,23806,23834,23111,15004,15017,15018,15019,15021,15025,15028,15031,15034,15035,15045,15046,15047,15053,15054,15055,15056,15057,15060,15064,15071,15078,15081,15082,15084,15088,15102,15104,15106,15108,15110,15112,15116,15120,15122,15123,15126,15127,15129,15131,15132,15133,15134,15135,15136,15137,15139,15140,15142,15143,15145,15146,15147,15148,15201,15202,15203,15204,15205,15206,15207,15208,15209,15210,15211,15212,15213,15214,15215,15216,15217,15218,15219,15220,15221,15222,15223,15224,15225,15226,15227,15228,15229,15230,15231,15232,15233,15234,15235,15236,15237,15239,15240,15241,15242,15243,15244,15250,15251,15252,15253,15254,15255,15257,15258,15259,15260,15261,15262,15264,15265,15267,15268,15270,15272,15274,15275,15276,15277,15278,15279,15281,15282,15283,15286,15289,15290,15295,15301,15312,15317,15321,15323,15339,15340,15342,15350,15361,15363,15365,15367,15376,15378,15379,15347,15330,43711,43717,43722,43723,43724,43725,43732,43736,43772,43778,43779,43780,43788,25504,25510,25526,25537,25541,25545,25559,25571,25701,25702,25703,25704,25705,25706,25707,25708,25709,25710,25711,25712,25713,25714,25715,25716,25717,25718,25719,25720,25721,25722,25723,25724,25725,25726,25727,25728,25729,25755,25770,25771,25772,25773,25774,25775,25776,25777,25778,25779,41101,41102,41105,41114,41129,41139,41169,41183,45619,45619,45623,45638,45645,45669,45675,45680,25011,25026,25033,25070,25082,25109,25112,25124,25143,25156,25159,25168,25177,25213,25334,25338,25357,25375,25389,25560,25569,25003,25015,25025,25035,25039,25045,25054,25061,25064,25067,25071,25075,25079,25083,25086,25102,25103,25107,25110,25126,25132,25134,25160,25162,25201,25202,25214,25301,25302,25303,25304,25305,25306,25309,25311,25312,25313,25314,25315,25317,25320,25321,25322,25323,25324,25325,25326,25327,25328,25329,25330,25331,25332,25333,25335,25336,25337,25339,25350,25356,25358,25360,25361,25362,25364,25365,25387,25392,25396,15001,15003,15005,15009,15010,15026,15027,15042,15043,15050,15052,15059,15061,15066,15074,15077,15081,16123,16136,16101,16102,16103,16105,16107,16108,16112,16115,16116,16117,16120,16121,16123,16132,16140,16141,16142,16143,16146,16148,16150,16155,16156,16157,16159,16160,16161,16172,44401,44403,44405,44406,44416,44418,44420,44422,44424,44425,44429,44430,44436,44437,44438,44440,44442,44443,44446,44451,44452,44454,44470,44471,44473,44481,44482,44483,44484,44485,44486,44488,44501,44502,44503,44504,44505,44506,44507,44509,44510,44511,44512,44513,44514,44515,44555,44619,44672,16001,16002,16003,16016,16017,16018,16020,16021,16022,16023,16024,16025,16027,16029,16030,16033,16034,16035,16037,16038,16039,16040,16041,16045,16046,16048,16050,16051,16052,16053,16055,16056,16057,16059,16061,16063,16066,15006,15007,15014,15015,15024,15030,15032,15037,15044,15049,15051,15065,15075,15076,15086,15090,15091,15101,15144,15238,44609,44701,44702,44703,44704,44705,44706,44707,44708,44709,44710,44711,44714,44718,44720,44720,44721,44730,44730,44735,44750,44767,44799,44601,44646,44647,44648,44608,44613,44614,44626,44630,44632,44640,44641,44643,44650,44652,44657,44662,44666,44669,44670,44685,44688,44689,44056,44067,44087,44203,44210,44216,44221,44222,44223,44224,44232,44232,44236,44237,44250,44260,44262,44264,44278,44286,44301,44302,44303,44304,44305,44306,44307,44308,44309,44310,44311,44313,44314,44315,44316,44317,44319,44320,44321,44325,44326,44328,44333,44334,44334,44372,44396,44398,44632,44685,44280,44256,44254,44281,44273,44258,44274,44233,44215,44235,44251,44253,44212,44282,44275,44240]; // add as many zip codes as you like, separated by commas (no comma at the end)
var found = false;
for (var i=0; i<codes.length; i++) {
if (zv == codes[i]) {
found = true;
break;
}
}
if (!found) {
alert("Sorry, the Zip Code " + zv + " is not covered by our business");
return false;
//do nothing
} else {
alert("The Zip Code " + zv + " is covered by our service team. Please press okay to go forward to schedule an appointment");
document.myform.submit();
}
}
</script>
Change onsubmit="checkZip()" to onsubmit="return checkZip()", because right now your form is always submitted.

Categories

Resources