Javascript stops working when add another javascript code - javascript

I am using this js code to validate a proper email is enetered into a form. If not, an warning box pops up.
function validateForm() {
var valid = true;
var errMsg = "";
var email = document.emailform.email.value;
//var fname = document.emailform.fname.value;
var filter = /^([a-zA-Z0-9_.-])+#(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
//if(fname.length <= 0) {
//valid = false;
//errMsg += "Please provide a valid first name.\n";
//}
if(email.length <= 0) {
valid = false;
errMsg += "Email address is required.\n";
} else {
if (!filter.test(email)) {
valid = false;
errMsg += "Please provide a valid email address.\n";
}
}
if (errMsg.length > 0) {
alert(errMsg);
return false;
}
}
Before my closing I have this...
<script>$('#awform').submit(validateForm);</script>
That works just fine.
I have another javascript code that I generally enter before the closing body tag, which works fine under normal circumstances.
<script language="JavaScript" type="text/javascript"> cbr202=Math.random()*10000000000000000;document.write('<scr'+'ipt language="JavaScript" src="http://mywebsite.com/track/static/landing.php?lpip=123&202cb='+cbr202+'" type="text/javascript"></scr' + 'ipt>'); </script>
This last piece is for a custom analytics program I use.
The problem I'm running into is that when I use the two scripts together, the validation no longer works.
So I do...
<script language="JavaScript" type="text/javascript"> cbr202=Math.random()*10000000000000000;document.write('<scr'+'ipt language="JavaScript" src="http://mywebsite.com/track/static/landing.php?lpip=123&202cb='+cbr202+'" type="text/javascript"></scr' + 'ipt>'); </script>
<script>$('#awform').submit(validateForm);</script>
</body>
As requested, here's what the tracking script looks like....
function t202Init(){
//this grabs the cid, but if they set a forced kw, this will be replaced
if (readCookie('t202forcedkw')) {
var cid = readCookie('t202forcedkw');
} else {
var cid = t202GetVar('cid');
}
var lpip = '<? echo htmlentities($_GET['lpip']); ?>';
var campid = t202GetVar('campid');
var OVRAW = t202GetVar('OVRAW');
var OVKEY = t202GetVar('OVKEY');
var OVMTC = t202GetVar('OVMTC');
var c1 = t202GetVar('c1');
var c2 = t202GetVar('c2');
var c3 = t202GetVar('c3');
var c4 = t202GetVar('c4');
var target_passthrough = t202GetVar('target_passthrough');
var keyword = t202GetVar('keyword');
var referer = document.referrer;
var resolution = screen.width+'x'+screen.height;
var language = navigator.appName=='Netscape'?navigator.language:navigator.browserLanguage;
language = language.substr(0,2);
document.write("<script src=\"<?php echo $strProtocol; ?>://<? echo $_SERVER['SERVER_NAME']; ?>/jump/static/record.php?lpip=" + t202Enc(lpip)
+ "&campid=" + t202Enc(campid)
+ "&cid=" + cid
+ "&OVRAW=" + t202Enc(OVRAW)
+ "&OVKEY=" + t202Enc(OVKEY)
+ "&OVMTC=" + t202Enc(OVMTC)
+ "&c1=" + t202Enc(c1)
+ "&c2=" + t202Enc(c2)
+ "&c3=" + t202Enc(c3)
+ "&c4=" + t202Enc(c4)
+ "&target_passthrough=" + t202Enc(target_passthrough)
+ "&keyword=" + t202Enc(keyword)
+ "&referer=" + t202Enc(referer)
+ "&resolution=" + t202Enc(resolution)
+ "&language=" + t202Enc(language)
+ "\" type=\"text/javascript\" ></script>"
);
}
function t202Enc(e){
return encodeURIComponent(e);
}
function t202GetVar(name){
get_string = document.location.search;
return_value = '';
do {
name_index = get_string.indexOf(name + '=');
if(name_index != -1) {
get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
end_of_value = get_string.indexOf('&');
if(end_of_value != -1) {
value = get_string.substr(0, end_of_value);
} else {
value = get_string;
}
if(return_value == '' || value == '') {
return_value += value;
} else {
return_value += ', ' + value;
}
}
}
while(name_index != -1)
//Restores all the blank spaces.
space = return_value.indexOf('+');
while(space != -1) {
return_value = return_value.substr(0, space) + ' ' +
return_value.substr(space + 1, return_value.length);
space = return_value.indexOf('+');
}
return(return_value);
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
t202Init();

Try switching the order of the two scripts. It seems that the custom analytics program is running document.write which is a bit nasty and may cause the rest of the document to not be parsed correctly.
Why is document.write considered a "bad practice"?.

Your embedded Javascript tags can break your script. Whenever I try to do a script of the form:
<script>
// Some stuff here
<script>
// More stuff here
</script>
</script>
The script breaks. Try using a different method to load your analytics.

Why not using jQuery to add the script-tag. You obviously have jQuery included.
Try
<script type="text/javascript">
var cbr202 = Math.random() *10000000000000000;
$('head').append('<scr'+'ipt type="text/javascript" src="http://mywebsite.com/track/static/landing.php?lpip=123&202cb='+cbr202+'" />');​
</script>

Related

Cookie Consent blocking rest of JavaScripts

I got this library from google, this cookie consent script. It works well but the problem is that untill you press the button and refresh the page the rest of javascripts won't work, so my navigation on phone isn't working neither the data-scroll animation. This is the code. I don't know where the problem is, if somebody could help me I would be thankful. Have a great day!
// --- Config --- //
var purecookieTitle = 'Cookies.'; // Title
var purecookieDesc =
'Acest website folosește cookie-uri pentru a vă îmbunătăți experiența. Folosind site-ul nostru web, sunteți de acord cu toate cookie-urilor în conformitate cu politica noastră de confidențialitate.'; // Description
var purecookieLink =
'Citesțe mai mult'; // Cookiepolicy link
var purecookieButton = 'Am înțeles'; // Button text
// --- --- //
function pureFadeIn(elem, display) {
var el = document.getElementById(elem);
el.style.opacity = 0;
el.style.display = display || 'block';
(function fade() {
var val = parseFloat(el.style.opacity);
if (!((val += 0.02) > 1)) {
el.style.opacity = val;
requestAnimationFrame(fade);
}
})();
}
function pureFadeOut(elem) {
var el = document.getElementById(elem);
el.style.opacity = 1;
(function fade() {
if ((el.style.opacity -= 0.02) < 0) {
el.style.display = 'none';
} else {
requestAnimationFrame(fade);
}
})();
}
function setCookie(name, value, days) {
var expires = '';
if (days) {
var date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
expires = '; expires=' + date.toUTCString();
}
document.cookie = name + '=' + (value || '') + expires + '; path=/';
}
function getCookie(name) {
var nameEQ = name + '=';
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
document.cookie = name + '=; Max-Age=-99999999;';
}
function cookieConsent() {
if (!getCookie('purecookieDismiss')) {
document.body.innerHTML +=
'<div class="cookieConsentContainer" id="cookieConsentContainer"><div class="cookieTitle"><a>' +
purecookieTitle +
'</a></div><div class="cookieDesc"><p>' +
purecookieDesc +
' ' +
purecookieLink +
'</p></div><div class="cookieButton"><a onClick="purecookieDismiss();">' +
purecookieButton +
'</a></div></div>';
pureFadeIn('cookieConsentContainer');
}
}
function purecookieDismiss() {
setCookie('purecookieDismiss', '1', 14);
pureFadeOut('cookieConsentContainer');
}
window.onload = function () {
cookieConsent();
};
Just in case someone else stumble upon this issue, the problem is in this line:
document.body.innerHTML +=
If you replace it with this, for example, it works perfectly and does not block any other javascript, but obviously you have to add the id footer somewehere in your page
document.getElementById("footer").innerHTML+=
In your HTML, put any div and assign an id to it:
<div class="any" id="footer"></div>
...
In the JS file, in the cookieConsent() function, change
document.body.innerHTML += to document.getElementById('footer').innerHTML +=.
The complete code would look like this:
function cookieConsent() {
if (!getCookie('purecookieDismiss')) {
document.getElementById('footer').innerHTML +=
'<div class="cookieConsentContainer" id="cookieConsentContainer"><div class="cookieTitle"><a>' +
purecookieTitle +
'</a></div><div class="cookieDesc"><p>' +
purecookieDesc +
'' +
purecookieLink +
'</p></div><div class="cookieButton"><a onClick="purecookieDismiss();">' +
purecookieButton +
'</a></div></div>';
pureFadeIn('cookieConsentContainer');
}
}
Sorry for my bad English ;(

Why does "\n" create a new line even when told not to?

I am having a problem with "\n" creating a line even when it is told not to when copying. The fix is probably something simple that I am just not seeing for some reason. I would appreciate any input or coaching on this problem.
(Please only give me Javascript answers as I am not interested in jquery or other methods)
<script type="text/javascript">
if (pullDownResponseE == "")
{
}
else {
var pullDownValuesE = document.getElementById("taskOne");
var pullDownResponseE = pullDownValuesE.options[pullDownValuesE.selectedIndex].value;
stuffToCopy = stuffToCopy + "\n" + pullDownResponseE;
}
if (pullDownResponseF == "")
{
}
else{
var pullDownValuesF = document.getElementById("taskTwo");
var pullDownResponseF = pullDownValuesF.options[pullDownValuesF.selectedIndex].value;
stuffToCopy = stuffToCopy + "\n" + pullDownResponseF;
}
</script>
As you can see, pullDownResponseF and pullDownReponseE should do nothing if my dropdown value equals "" and this portion works for the most part, it doesn't execute any of the else code EXCEPT for the new line "\n" part.
Can anyone explain what is going wrong here?
EDIT: Having more code might help here. I'll only include the essential portions since it is so long.
<script type="text/javascript">
function copyNotesTemplate()
{
var stuffToCopy = document.getElementById('myForm').value;
if(stuffToCopy.length > 1)
{
var stuffToCopy = "PT meets criteria" + "\n" + document.getElementById('myForm').value;
}
if(document.getElementById('noPtCriteria').checked)
{
var stuffToCopy = document.getElementById('noPtCriteria').value;
}
if (pullDownResponsee == "")
{
}
else {
var pullDownValuese = document.getElementById("taskOne");
var pullDownResponsee = pullDownValuese.options[pullDownValuese.selectedIndex].value;
stuffToCopy = stuffToCopy + "\n" + pullDownResponsee;
}
if (pullDownResponsef == "")
{
}
else{
var pullDownValuesf = document.getElementById("taskTwo");
var pullDownResponsef = pullDownValuesf.options[pullDownValuesf.selectedIndex].value;
stuffToCopy = stuffToCopy + "\n" + pullDownResponsef;
}
if (pullDownResponseg == "")
{
}
else{
var pullDownValuesg = document.getElementById("taskThree");
var pullDownResponseg = pullDownValuesg.options[pullDownValuesg.selectedIndex].value;
stuffToCopy = stuffToCopy + "\n" + pullDownResponseg;
}
var tempValues = document.getElementById('whatUpdate').value
if(tempValues.length > 1)
{
var stuffToCopy = stuffToCopy + "Updated" + " " + document.getElementById('whatUpdate').value + " ";
}
else{
}
var tempValuess = document.getElementById('whatInfo').value
if(tempValuess.length > 1)
{
var stuffToCopy = stuffToCopy + "per" + " " + document.getElementById('whatInfo').value + "\n";
}
else{
}
var tempValue = document.getElementById('whatDSCRP').value
if(tempValue.length > 1)
{
var stuffToCopy = stuffToCopy + document.getElementById('whatDSCRP').value + " " + "dscrp on Collection tube and trf was resolved using" + " ";
}
else{
}
var tempValue = document.getElementById('resolveIT').value
if(tempValue.length > 1)
{
var stuffToCopy = stuffToCopy + document.getElementById('resolveIT').value + " ";
}
else{
}
var tempValue = document.getElementById('tubeCorrect').value
if(tempValue.length > 1)
{
var stuffToCopy = stuffToCopy + "trf was" + " " + document.getElementById('tubeCorrect').value;
}
else{
}
if(stuffToCopy.length > 1)
{
var stuffToCopy = stuffToCopy + "\n" + document.getElementById('moreNotes').value;
}
else{
}
if (pullDownResponsesu == "")
{
}
else{
var pullDownValuesu = document.getElementById("mod33Apply");
var pullDownResponsesu = pullDownValuesu.options[pullDownValuesu.selectedIndex].value;
stuffToCopy = stuffToCopy + "\n" + pullDownResponsesu;
}
if (pullDownResponsesb == "")
{
}
else{
var pullDownValuesb = document.getElementById("resultICR");
var pullDownResponsesb = pullDownValuesb.options[pullDownValuesb.selectedIndex].value;
stuffToCopy = stuffToCopy + "\n" + pullDownResponsesb + "," + " ";
}
if (pullDownResponsesc == "")
{
}
else{
var pullDownValuesc = document.getElementById("moneyNCIS");
var pullDownResponsesc = pullDownValuesc.options[pullDownValuesc.selectedIndex].value;
stuffToCopy = stuffToCopy + pullDownResponsesc + " ";
}
if (pullDownResponsesd == "")
{
}
else{
var pullDownValuesd = document.getElementById("resultMMT");
var pullDownResponsesd = pullDownValuesd.options[pullDownValuesd.selectedIndex].value;
stuffToCopy = stuffToCopy + pullDownResponsesd;
}
if(stuffToCopy.length > 1)
{
var stuffToCopy = stuffToCopy + " " + "Reason:" + " " + document.getElementById('whyNotEligible').value;
}
else{
}
if (pullDownResponsesa == "")
{
}
else{
var pullDownValuesa = document.getElementById("testReleased");
var pullDownResponsesa = pullDownValuesa.options[pullDownValuesa.selectedIndex].value;
stuffToCopy = stuffToCopy + "\n" + pullDownResponsesa;
}
window.clipboardData.setData('text', stuffToCopy);
}
</script>
If somebody skips filling out a note field or skips a dropdown in this example then it will not execute the code like I intended but it does create a new line when copied like this:
taskOne selected
(extra line here since task two wasn't selected)
taskThree selected
I would like there not to be an extra line between Task one and three if task two is skipped. Like this:
taskOne selected
taskThree selected
Note: I know that having else {} is pointless but it helps me visually.
I created snips of exactly what it looks like when copy/pasted from my tool that you can view here if you would like:
Example 1: http://imgur.com/wGO5vnT
Example 2: http://imgur.com/UX1tG5S
Here is an example of my html as well:
<html lang="en">
What tasks are needed for the case?
<br />
<select class="style3" id="taskOne">
<option value=""></option>
<option value="ABN needed">ABN needed</option>
<option value="Auth needed">Auth needed</option>
</select>
</html>
No, it doesn't add a new line, see:
stuffToCopy = "";
controlGroup = "a\nb";
pullDownResponseE = "";
if (pullDownResponseE == "")
{
}
else {
var pullDownValuesE = "taskOne";
var pullDownResponseE = "value";
stuffToCopy = stuffToCopy + "\n" + pullDownResponseE;
}
alert("stuffToCopy:"+stuffToCopy+";(no new-line here)\ncontrolGroup:"+controlGroup);
My guess is that your html is printed in such away that the values you get from the inputs contain an extra new-line at the end. Try changing your html to be 1 line, without new-lines, and test again.
Instead of:
<option value="a
">b
</option>
try:
<option value="a">b</option>
Alright so I fixed it, should have used the almighty document.getElementById instead of attempting to use pullDownReponse for my if statements..
I simply changed the if statements like this:
if (pullDownResponseg == "")
{
}
To this:
if (document.getElementById("taskThree").value == "")
{
}
Thanks for the help from the sincere. (and ridiculous non-answers from the others)

document.write() Is Removing All Page Content When Calling After Page Load

I have a web page where I am reading Google Blogger blog category from his feed using JSON. I have two functions. First on is getting all the Blog Categories List and second one is taking Blog Categories from that and then hitting again Blog to get latest posts from that This is the text test to see that web page data is here or not.
<div id="blogCategoriesList">
<script type="text/javascript">
var blogurl = "https://googleblog.blogspot.com/";
function blogCatList(json) {
document.write('<select onchange="showThisCatPosts(this.value)">');
document.write('<option>CHOOSE A CATEGORY</option>');
for (var i = 0; i < json.feed.category.length; i++)
{
var item = "<option value='" + json.feed.category[i].term + "'>" + json.feed.category[i].term + "</option>";
document.write(item);
}
document.write('</select>');
}
document.write('<script type=\"text/javascript\" src=\"' + blogurl + '/feeds/posts/default?redirect=false&orderby=published&alt=json-in-script&callback=blogCatList&max-results=500\"><\/script>');
document.write('<br/><br/><a href=\"' + blogurl + '\" target=\"_blank\" class=\"footerLINK\">Read The Blog Online Now<\/a>');
</script>
</div>
<div id="blogCategoriesPost">
<script style='text/javascript'>
var blogurl = "https://googleblog.blogspot.com/";
var numposts = 10; // Out Of 500
var displaymore = true;
var showcommentnum = true;
var showpostdate = true;
var showpostsummary = true;
var numchars = 100;
function blogCategoriesPost(json) {
if(json.feed.entry.length < numposts ){
numposts = json.feed.entry.length;
}
for (var i = 0; i < numposts; i++) {
var entry = json.feed.entry[i];
var posttitle = entry.title.$t;
var posturl;
if (i == json.feed.entry.length) break;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'replies' && entry.link[k].type == 'text/html') {
var commenttext = entry.link[k].title;
var commenturl = entry.link[k].href;
}
if (entry.link[k].rel == 'alternate') {
posturl = entry.link[k].href;
break;
}
}
var postdate = entry.published.$t;
var cdyear = postdate.substring(0, 4);
var cdmonth = postdate.substring(5, 7);
var cdday = postdate.substring(8, 10);
var monthnames = new Array();
monthnames[1] = "Jan";
monthnames[2] = "Feb";
monthnames[3] = "Mar";
monthnames[4] = "Apr";
monthnames[5] = "May";
monthnames[6] = "Jun";
monthnames[7] = "Jul";
monthnames[8] = "Aug";
monthnames[9] = "Sep";
monthnames[10] = "Oct";
monthnames[11] = "Nov";
monthnames[12] = "Dec";
document.write('<div id="mainDIV">');
document.write('<h2 class="post_heading">' + posttitle + '</h2>');
if ("content" in entry) {
var postcontent = entry.content.$t;
} else
if ("summary" in entry) {
var postcontent = entry.summary.$t;
} else var postcontent = "";
var re = /<\S[^>]*>/g;
postcontent = postcontent.replace(re, ""); // Will Show Only Text Instead Of HTML
if (showpostsummary == true) {
if (postcontent.length < numchars) {
document.write('<span class="post_summary">');
document.write(postcontent);
document.write('</span>');
} else {
//document.getElementById("catPosts").innerHTML += '<span class="post_summary">';
document.write('<span class="post_summary">');
postcontent = postcontent.substring(0, numchars);
var quoteEnd = postcontent.lastIndexOf(" ");
postcontent = postcontent.substring(0, quoteEnd);
document.write(postcontent + '...');
document.write('</span>');
}
}
var towrite = '';
document.write('<strong class="post_footer">');
if (showpostdate == true) {
towrite = 'Published On: ' + towrite + monthnames[parseInt(cdmonth, 10)] + '-' + cdday + '-' + cdyear;
}
if (showcommentnum == true) {
if (commenttext == '1 Comments') commenttext = '1 Comment';
if (commenttext == '0 Comments') commenttext = 'No Comments';
commenttext = '<br/>' + commenttext + '';
towrite = towrite + commenttext;
}
if (displaymore == true) {
towrite = towrite + '<br/>Read Full Article -->';
}
document.write(towrite);
document.write('</strong></div>');
}
}
function showThisCatPosts(BLOGCAT){
document.write('<script type=\"text/javascript\" src=\"' + blogurl + '/feeds/posts/default/-/' + BLOGCAT + '?redirect=false&orderby=published&alt=json-in-script&callback=blogCategoriesPost&max-results=500\"><\/script>');
document.write('<a href=\"' + blogurl + '\" target=\"_blank\" class=\"footerLINK\">Read The Blog Online Now<\/a>');
}
</script>
You can see a working DEMO at JSBIN. My problem is that when page load, its works perfectly showing all page data and the blog categories lists too but when I select any category then my all page data remove and only that label posts are visible. Why this is happening...??? I want to just change the posts as per label not to remove all page data...
That's the normal behaviour of document.write(). You might need to use:
document.getElementById("element_id").innerHTML = 'Stuff to Write.';
Finally I got it solved. The reason is that document.write() is bad as it write the text on page load. You can use it if you want to write some text on page load not later.
If you want to write later then have to use document.getElementById("element_id").innerHTML to write your text but if you want to write <script> tags then document.getElementById("element_id").innerHTML is not good as it will write but dont hit the SRC so use document.createElement("script") to write scripts after page load that will be runable too.
See the working DEMO of my code at JSBIN... :)
Special Thanks To: #Praveen Kumar :-)

How can I pass time using jquery

I have 2 pages. On page 1 i have two values, one is string and one is datetime.
I want to pass that value to page 2 but i have problem, the string is passed but datetime is not passed. This is my code
time = jQuery('#timepicker_7').val();
var url = "test.aspx?name=" + encodeURIComponent(lObjSeat[0].Name) + "&technology=" + encodeURIComponent(time);
window.location.href = url;
this is what's on page 2
<script type="text/javascript">
var queryString = new Array();
$(function () {
if (queryString.length == 0) {
if (window.location.search.split('?').length > 1) {
var params = window.location.search.split('?')[1].split('&');
for (var i = 0; i < params.length; i++) {
var key = params[i].split('=')[0];
var value = decodeURIComponent(params[i].split('=')[1]);
queryString[key] = value;
}
}
}
if (queryString["name"] != null) {
var data = "<u>Values from QueryString</u><br /><br />";
data += "<b>Name:</b> " + queryString["name"] + " <b>Technology:</b> " + queryString["technology"];
$("#lblData").html(data);
}
});
"name" is done. but "time" is not show. whats the problem ?

Google Script Invalid Assignment left-hand side

Ok so I have this code. Sorry, I didn't know where the problem is so I pasted it all. It says: Invalid assignment left-hand side. (line 1, file "Code"). I know the problem cannot be on line one but have no idea where it is.
function send(sheet, email, row){
var tmp = GmailApp.getAliases();
var alias = tmp[0];
var subject = "Thank you for signing up for "+ sheet.getSheetName()+ "!";
var body = "Hello "+ sheet.getRange(row,3).getValue() + " " + sheet.getRange(row,4).getValue() + "," + '\n'+'\n';
var temp = 2;
var bool = "TRUE";
while (bool == "TRUE"){
if (sheet.getRange(temp,11).getValue() != ''){
body += '\n' + sheet.getRange(temp,11);
temp += 1;
}
if (sheet.getRange(temp + 1,11).getValue() != '')
body += '\n' + body += '\n' + sheet.getRange(temp + 1,11);
else {bool = "FALSE"}
}
Logger.log(body);
if ( sheet.getRange('L2').getValue() != ""){
var html = sheet.getRange('L2').getValue(); // Place HTML code here
try {
GmailApp.sendEmail(email, subject, body, {'from': alias, 'htmlbody': html});
sheet.getRange(row, 9).setBackground("green");
sheet.getRange(row, 9).setValue("Yes");
sheet.getRange("J2").setValue(row - 2);
} catch (e) {
var me = Session.getActiveUser().getEmail();
MailApp.sendEmail(me, "Autoreply error", "There was a problem sending an email to: " + email +".");
}
}
else{
try {
GmailApp.sendEmail(email, subject, body, {'from': alias});
sheet.getRange(row, 9).setBackground("green");
sheet.getRange(row, 9).setValue("Yes");
sheet.getRange("J2").setValue(row - 2);
} catch (e) {
MailApp.sendEmail(me, "Autoreply error", "There was a problem sending an email to: " + email +".");
}
}
}
function main(){
var ss = SpreadsheetApp.openById("1a2xvZ6hx69hst0CoLnCc8V5Igi-V5_HaNm6GTpEU8B4"); // Unique ID for the 'Responses' spreadsheet
var sheet = ss.getActiveSheet();
if ( sheet.getRange('J2').getValue() == "" ){
sheet.getRange('I1').setValue("Sent"); // Initialize labels
sheet.getRange('J1').setValue("Count");
sheet.getRange('K1').setValue("Email body");
sheet.getRange('L1').setValue("HTML body");
var row = 2;
} else {
var row = sheet.getRange("J2").getValue() + 2;
}
while ( (sheet.getRange(row,9).getValue() != '') && (sheet.getRange(row,2).getValue() != '')) {
var email = sheet.getRange(row, 2).getValue();
send(sheet, email, row);
row += 1;
}
}
You cannot write a line like this : ( 2 x += in the same statement)
body += '\n' + body += '\n' + sheet.getRange(temp + 1,11); // this throws the error
I'd suggest to use an intermediate variable like this :
var xxx = '\n' + sheet.getRange(temp + 1,11);
body+= '\n'+ body + xxx ;
if this is really what you want to do... but it seems strange to me...
Shouldn't it be something like this : body+= '\n'+sheet.getRange(temp + 1,11);

Categories

Resources