Some weeks ago I developed a code that takes some information from a spreadsheet each time a user submit a form, and then, send me an email with the information completed. It works really well.
However, I am intending to add a Ticket number in the first column of the sheet (without adding it in the google form) but it is not being recognized by my code.
Do you have any clue about how could I add this first column to my email each time I receive a new submit?
I attach my code.
function formSubmitReply(e) {
// VARIABLES
var ticketNo;
var alUser = e.values[1];
var country = e.values[3];
var language = e.values[2];
var category = e.values[4];
var title = e.values[5];
var questions = e.values[6];
var attach = e.values[7];
var entityEn = e.values[8];
var categoryEn = e.values[9];
var titleEn = e.values[10];
var questionsEn = e.values[11];
var attachEn = e.values[12];
var userEmail = "nam.hr#airliquide.com";
var msgFr =
// Add table style and format the cells with th and tr
"<table border='1' border-radius='5px' style='border-collapse:collapse; font-family:sans-serif;'>" +
"<tr>" +
"<th>Employé AL</th>" +
"<th>Sélection du pays</th>" +
"<th>Langue préférée</th>" +
"<th>Catégorie</th>" +
"<th>Sujet</th>" +
"<th>Contenu de la demande</th>" +
"<th>Pièce jointe</th>" +
"<th>#</th>" +
"</tr>" +
"<tr>" +
"<td>" + alUser + "</td>" +
"<td>" + country + "</td>" +
"<td>" + language + "</td>" +
"<td>" + category + "</td>" +
"<td>" + title + "</td>" +
"<td>" + questions + "</td>" +
"<td>" + attach + "</td>" +
"<td>" + ticketNo + "</td>" +
"</tr>" +
"</table>";
var msgEn =
// Add table style and format the cells with th and tr
"<table border='1' style='border-collapse:collapse; font-family:sans-serif;'>" +
"<tr>" +
"<th>AL user</th>" +
"<th>Country</th>" +
"<th>Preferred Language</th>" +
"<th>Category</th>" +
"<th>Title</th>" +
"<th>Question</th>" +
"<th>Attachments</th>" +
"<th>#</th>" +
"</tr>" +
"<tr>" +
"<td>" + alUser + "</td>" +
"<td>" + entityEn + "</td>" +
"<td>" + language + "</td>" +
"<td>" + categoryEn + "</td>" +
"<td>" + titleEn + "</td>" +
"<td>" + questionsEn + "</td>" +
"<td>" + attachEn + "</td>" +
"<td>" + ticketNo + "</td>" +
"</tr>" +
"</table>";
MailApp.sendEmail({
to: userEmail,
subject: 'NAM HR Mailbox | ' + categoryEn + category,
htmlBody: (language=="English") ? msgEn : msgFr,
name: alUser,
replyTo: alUser
});
}
Solution:
You need to add the first column manually in the spreadsheet then add this code to fill up the values every form submit:
function formSubmitReply(e) {
var ss = SpreadsheetApp.getActive();
var id = e.range.getRow();
var startNum = 850; // to start the entries from T0850
var control = startNum + id - 2;
var ticketNo = "T"+control.toString().padStart(4,"0");
ss.getActiveSheet().getRange(id,1).setValue(ticketNo);
// VARIABLES
var alUser = e.values[1];
var country = e.values[3];
.....
The rest of the code should be the same as with your question.
Sample Output:
Having a few issues trying to get this function output to an ajax table (working fine) and an input box called connectsList1.
i cannot get it to spit out into the input box without error, the error is
Uncaught TypeError: Cannot set property 'innerHTML' of null
and
connectsList1 is not defined
function getConnections(txt1) {
func_getConnections(
function (response) {
var sortorder = txt1;
var arr = response;
var i;
var Count;
var mCount;
var oCount;
var out =
"<thead>"
for (i = 0; i < arr.length; i++) {
out +=
"<tr>" +
"<tbody>" +
"<tr class=\"" + ReturnValuesAsColor(arr[i].o, arr[i].m, arr[i].server_proc) + "\">" +
"<td>" + arr[i].id + "</td>" +
//"<td>" + arr[i].user_id + "</td>" +
"<td>" + arr[i].user_name + "</td>" +
"<td>" + arr[i].workstation_name + "</td>" +
"<td>" + (!!arr[i].ip_address ? arr[i].ip_address : '') + "</td>" +
"<td>" + formatDateTime(arr[i].connect_date, 'datelongtime') + "</td>" +
"<td>" + formatDateTime(arr[i].refresh_date, 'datelongtime') + "</td>" +
"<td>" + (!!arr[i].app_ver ? arr[i].app_ver : '') + "</td>" +
"<td>" + (!!arr[i].app_date ? formatDateTime(arr[i].app_date, 'shortdate') : '') + "</td>" +
"<td>" + Messages_flag(arr[i].get_messages_flag) + "</td>" +
"<td>" + FixNumbers(arr[i].message_type_flags) + "</td>" +
//"<td>" + arr[i].o + "</td>" +
//"<td>" + arr[i].m + "</td>" +
"<td>" + arr[i].group_name + "</td>" +
//"<td>" + arr[i].server_proc + "</td>" +
"<td> <button id=\"DelImg1\" type=\"button\" name=\"btnsubmit\" class=\"ui-button ui-widget ui-state-default ui-corner-all\" onclick=\"clearText('<%= result.ClientID%>'); CopyId(" + arr[i].id + "); return Message(" + arr[i].id + ")\" >Delete</button> </td>" +
"</tr>" +
"</tbody>";
mCount = 0
if (arr[i].m != 0) {
mCount += 1;
} else if (arr[i].o != 0) {
oCount += +1;
} else if (arr[i].o == 0 & arr[i].m == 0) {
Count += 1;
}
document.getElementById("dtBody1").innerHTML = out;
document.getElementById('ConnectsList1').innerHTML = out;
ConnectsList1 = " Connection list: " & Count + oCount + mCount & " connection(s) Main Application : " & Count & " Online : " & oCount & " Mobile : " & mCount;
}})};
Any help or advice welcome, still learning ajax myself
document.getElementById("dtBody1") can not find any tag with id dtBody1. Make sure your HTML has an element with that ID.
And remember to declare the ConnectsList1 variable to avoid the second error.
I want to create a button that produces a 3x3 HTML table meant for a card game, where each cell corresponds to one single image. For the time being, I'm mainly focusing on filling individual cells with a card number taken from an array element, using a step-by-step rationale. This is what the final result should look like in HTML, derived from the produced script;
<table style="width:100%">
<tr>
<td><img src="1.png"></td>
<td><img src="2.png"></td>
<td><img src="3.png"></td>
</tr>
<tr>
<td><img src="4.png"></td>
<td><img src="5.png"></td>
<td><img src="6.png"></td>
</tr>
<tr>
<td><img src="7.png"></td>
<td><img src="8.png"></td>
<td><img src="9.png"></td>
</tr>
</table>
This is what I'm currently working at, although with not much success
<!DOCTYPE html>
<html>
<body>
<table id="1">
</table>
<button onclick="createTable()">Create</button>
<script>
function createTable() {
var deck = [1,2,3,4,5,6,7,8,9];
function shuffle(o) { //v1.0
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
}
shuffle(deck);
document.getElementById("1").innerHTML = "<tr><td>" + deck[0] + "</td><td>" + deck[1] + "</td><td>" + deck[2] + "</td></tr>" +
"<tr><td>" + deck[3] + "</td><td>" + deck[4] + "</td><td>" + deck[5] + "</td></tr>" +
"<tr><td>" + deck[6] + "</td><td>" + deck[7] + "</td><td>" + deck[8] + "</td></tr>" +
;
}
</script>
</body>
</html>
Note
The 9-card deck is shuffled using a pretty basic and self-explanatory function.
Edit. My final version, which is returning broken image.
<!DOCTYPE html>
<html>
<body>
<table id="1">
</table>
<button onclick="createTable()">Create</button>
<script>
function createTable() {
var deck = [1,2,3,4,5,6,7,8,9];
function shuffle(o) {
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
}
shuffle(deck);
document.getElementById("1").innerHTML = "<tr><td><img src=" + deck[0] + ".png'></td><td>" + deck[1] + "</td><td>" + deck[2] + "</td></tr>" +
"<tr><td>" + deck[3] + "</td><td>" + deck[4] + "</td><td>" + deck[5] + "</td></tr>" +
"<tr><td>" + deck[6] + "</td><td>" + deck[7] + "</td><td>" + deck[8] + "</td></tr>"
;
}
</script>
</body>
</html>
After you fix your code by removing the extra + at the last line where you build your html (tr's and td's), you will simply need just to replace
"<td>" + deck[0] + "</td>"
by
"<td><img src='" + deck[0] + ".png'></td>"
... and so on for other indexes like deck[1], deck[2] etc.
You have got an extra "+"
document.getElementById("1").innerHTML = "<tr><td>" + deck[0] + "</td><td>" + deck[1] + "</td><td>" + deck[2] + "</td></tr>" +
"<tr><td>" + deck[3] + "</td><td>" + deck[4] + "</td><td>" + deck[5] + "</td></tr>" +
"<tr><td>" + deck[6] + "</td><td>" + deck[7] + "</td><td>" + deck[8] + "</td></tr>";
Should work better.
Your shuffle() is pretty convoluted. Let me advise you to write less exotic code. Making your code more readable will help to find potential errors. Indeed, the problem is not so hard to locate actually: https://stackoverflow.com/a/34471591/1636522 :-)
var deck = [1, 2, 3, 4, 5, 6, 7, 8, 9];
document.write(JSON.stringify(shuffle(deck), 0, 1));
function shuffle (anArray) {
var i, j, x, l = anArray.length;
for (i = 0; i < l; i++) {
j = rdmInt(l);
x = anArray[i];
anArray[i] = anArray[j];
anArray[j] = x;
}
return anArray;
}
function rdmInt (max) {
return Math.floor(Math.random() * max);
}
The same remark applies to your string concatenation:
document.getElementById("1").innerHTML = ""
+ "<tr>"
+ "<td><img src=" + deck[0] + ".png'></td>"
+ "<td>" + deck[1] + "</td>"
+ "<td>" + deck[2] + "</td>"
+ "</tr>"
+ "<tr>"
+ "<td>" + deck[3] + "</td>"
+ "<td>" + deck[4] + "</td>"
+ "<td>" + deck[5] + "</td>"
+ "</tr>"
+ "<tr>"
+ "<td>" + deck[6] + "</td>"
+ "<td>" + deck[7] + "</td>"
+ "<td>" + deck[8] + "</td>"
+ "</tr>";
Can you see the error now (line 3)? Here is a fix:
+ "<td><img src=\"" + deck[0] + ".png\"></td>"
You could go even further to avoid repetitions (dry):
var deck = [
"KNhxd", "7CtbR", "Os8qX",
"21SKd", "CWMZC", "43C1X",
"lpGvK", "8Wk7W", "Y3JFi"
];
// preserve the global namespace with an IIFE
document.body.innerHTML = function () {
var ROOT = "http://i.stack.imgur.com/";
function toTable (deck) {
var i, html = "";
for (i = 0; i < 3; i++) {
html += toTr(deck.slice(i * 3, (i + 1) * 3));
}
return "<table>" + html + "</table>";
}
function toTr (row) {
return "<tr>" + row.map(toTd).join('') + "</tr>";
}
function toTd (cell) {
return "<td><img src=\"" + ROOT + cell + ".png\" /></td>";
}
return toTable(deck);
}();
body{background:#006600;}
img{display:block;width:35px;}
If you want to create HTML elements, then you do not just write them as a text string and insert into an existing HTML element.
You create an element node (and text node if applicable) and append that to your existing HTML element.
Here is an article on w3 schools about creatung HTML tags with JavaScript.
http://www.w3schools.com/jsref/met_document_createelement.asp
If your table is always 9 cells then why not just write the HTML out giving each cell a unique id. Then u could use code similar to what u have.
document.getElementById("cell_1").innerHTML = deck[0];
You would need to include this logic for all 9 cells / values, although you could loop through them like;
for (i = 0; i < 8; i++) {
var cellNo = i + 1;
document.getElementById("cell_" + cellNo).innerHTML = deck[i];
}
Hope this helps ;)
In addition to the unnecessary '+' at the end of your innerHTML addition,
I would suggest making your code more flexible. Instead of adding the data hardcoded to your innerHTML you can do something like this:
var endOfRowCounter = 0;
var toAppend = "";
deck.forEach(function(card){
if(endOfRowCounter % 3 == 0) {
toAppend += "<tr>";
}
toAppend += "<td><img src=\"" + card + ".png\"></td>";
if(endOfRowCounter % 3 == 2)
{
toAppend += "</tr>";
}
endOfRowCounter++;
});
When I load your code I get this message in the browser console:
Uncaught SyntaxError: Unexpected token ;
It might help if you update this code:
document.getElementById("1").innerHTML = "<tr><td>" + deck[0] + "</td><td>" + deck[1] + "</td><td>" + deck[2] + "</td></tr>" +
"<tr><td>" + deck[3] + "</td><td>" + deck[4] + "</td><td>" + deck[5] + "</td></tr>" +
"<tr><td>" + deck[6] + "</td><td>" + deck[7] + "</td><td>" + deck[8] + "</td></tr>" +
;
To this:
document.getElementById("1").innerHTML = "<tr><td>" + deck[0] + "</td><td>" + deck[1] + "</td><td>" + deck[2] + "</td></tr>" +
"<tr><td>" + deck[3] + "</td><td>" + deck[4] + "</td><td>" + deck[5] + "</td></tr>" +
"<tr><td>" + deck[6] + "</td><td>" + deck[7] + "</td><td>" + deck[8] + "</td></tr>";
To loop your array and create your table structure with the images, you could do this for example:
function createTable() {
var deck = [1,2,3,4,5,6,7,8,9];
function shuffle(o) { //v1.0
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
}
shuffle(deck);
var html = '';
for (var i = 0; i < deck.length; i++) {
if (i%3 === 0) {
html += "<tr>";
}
html += '<td><img src="' + deck[i] + '.png"></td>';
if (i%3 === 2) {
html += "</tr>";
}
}
document.getElementById("1").innerHTML = html;
}
I have button to add new row(s) to table.
In the table row have a column with touch spin.
I want to loop through Array(Items). to make a rows. But below code make a Error Uncaught TypeError: undefined is not a function at function tp0
function showtable() {
$('#showtable').html("");
for(var i in Items) {
var no = parseInt($('#tb tr').length) - 1;
var data = "<tr role='row' class='filter' >"
+ "<td>" + no
+ "</td>"
+ "<td>"
+ "<div class='form-group'>"
+ "<input id='touch" + i + "' type='text' value='1' name='touch" + i + "' /> "
+ "<script>"
+ "function tp" + i + " () {$(\"input[name=\'touch" + i + "\']\").TouchSpin(); alert('ttt');}"
+ "</scr" + "ipt>"
+ "</div>"
+ "</td>"
+ "</tr>";
$('#showtable').append(data);
var method_name = "tp";
window[method_name + i]();
}
}
Have any ideas thanks
Instead of adding functions like that with each row, you should just pass the row number as a variable to a predefined function:
function tp(index) {
$("input[name='touch" + index + "']").TouchSpin();
alert('ttt');
}
function showtable() {
$('#showtable').html("");
for (var i in Items) {
var no = parseInt($('#tb tr').length) - 1;
var data = "<tr role='row' class='filter' >"
+ "<td>" + no
+ "</td>"
+ "<td>"
+ "<div class='form-group'>"
+ "<input id='touch"+i+"' type='text' value='1' name='touch"+i+"' /> "
+ "</div>"
+ "</td>"
+ "</tr>";
$('#showtable').append(data);
tp(i);
}
}
how do I integrate a type of validation in my JavaScript to the idea of If value of var firstName is = to null do NOT append the var sHtml and summaryHtml and change the class to change the textbox border and clear the field
rules:
firstName = must contain at least 1 letter and no more than 15 letters
lastName = must contain at least 1 letter and no more than 15 letters
jobTitle = must contain something other than an option value of "" (in the html option tag)
eSculation = must contain something other than an option value of "" (in the html option tag)
mobilePhone = must contain 9 numbers. This field has a mask attached: (999) 999-99999
officePhone = = must contain 9 numbers. This field has a mask attached: (999) 999-99999
eMail = Must contain the following symbol: an # sign and a . to represent xxx#xx.xxx
The JavaScript I am using to submit to a table is below:
newRow = 1;
currentRow = -1;
function CompanyContacts() {
var rowID = parseInt(document.getElementById("ContactsRowCount").value, 10);
rowID++;
if (currentRow > 0) {
saveEdits();
} else {
var firstName = $("#ccFirst").val();
var lastName = $("#ccLast").val();
var jobTitle = $("#ccjTitle").val();
var eSculation = $("#ccEsculation").val();
var mobilePhone = $("#ccMobile").val();
var officePhone = $("#ccOffice").val();
var eMail = $("#ccEmail").val();
var sHtml = "<tr id='row" + rowID + "'>" +
"<td class='tblStyle68wlb' id=\"ccFirst" + rowID + "\">" + firstName + "</td>" +
"<input type=\"hidden\" value=\"" + firstName + "\" name=\"cFirst" + rowID + "\" />" +
"<td class='tblStyle68wl' id=\"ccLast" + rowID + "\">" + lastName + "</td>" +
"<input type=\"hidden\" value=\"" + lastName + "\" name=\"cLast" + rowID + "\" />" +
"<td class='tblStyle68wlb' id=\"ccjTitle" + rowID + "\">" + jobTitle + "</td>" +
"<input type=\"hidden\" value=\"" + jobTitle + "\" name=\"cJobTitle" + rowID + "\" />" +
"<td class='tblStyle68wl' id=\"ccEsculation" + rowID + "\">" + eSculation + "</td>" +
"<input type=\"hidden\" value=\"" + eSculation + "\" name=\"cContactPoint" + rowID + "\" />" +
"<td class='tblStyle68wlb' id=\"ccMobile" + rowID + "\">" + mobilePhone + "</td>" +
"<input type=\"hidden\" value=\"" + mobilePhone + "\" name=\"cMobilePhone" + rowID + "\" />" +
"<td class='tblStyle68wl' id=\"ccOffice" + rowID + "\">" + officePhone + "</td>" +
"<input type=\"hidden\" value=\"" + officePhone + "\" name=\"cOfficePhone" + rowID + "\" />" +
"<td class='tblStyle68wlb' id=\"ccEmail" + rowID + "\">" + eMail + "</td>" +
"<input type='hidden' value='" + eMail + "' name='cEmail" + rowID + "' />" +
"<td class='tblStyle68wl' ><button type='button' class='XsmallButtons' onclick='editRow(" + rowID + ")'>Edit</button>" +
"</td><td class='tblStyle68wlb' ><button type='button' class='XsmallButtons' onclick='deleteRow(" + rowID + ")'>Delete</button>" +
"</td></tr>";
var summaryHtml = "<tr id='SummaryRow" + rowID + "'>" +
"<td id='ccFirst" + rowID + "'>" + firstName + "</td>" +
"<td id='ccLast" + rowID + "'>" + lastName + "</td>" +
"<td id='ccjTitle" + rowID + "'>" + jobTitle + "</td>" +
"<td id='ccEsculation" + rowID + "'>" + eSculation + "</td>" +
"<td id='ccMobile" + rowID + "'>" + mobilePhone + "</td>" +
"<td id='ccOffice" + rowID + "'>" + officePhone + "</td>" +
"<td id='ccEmail" + rowID + "'>" + eMail + "</td>" +
"</tr>";
$("#customerContactSubmitedTable").append(sHtml);
$("#SummaryCCTable").append(summaryHtml);
newRow++;
document.getElementById("ContactsRowCount").value = rowID;
$("#ccFirst,#ccLast,#ccjTitle,#ccEsculation,#ccMobile,#ccOffice,#ccEmail").val("");
}
}
function editRow(rowID) {
$('#ccFirst').val($('#ccFirst' + rowID).html());
$('#ccLast').val($('#ccLast' + rowID).html());
$('#ccjTitle').val($('#ccjTitle' + rowID).html());
$('#ccEsculation').val($('#ccEsculation' + rowID).html());
$('#ccMobile').val($('#ccMobile' + rowID).html());
$('#ccOffice').val($('#ccOffice' + rowID).html());
$('#ccEmail').val($('#ccEmail' + rowID).html());
currentRow = rowID;
}
function saveEdits() {
$('#ccFirst' + currentRow).html($('#ccFirst').val());
$('#ccLast' + currentRow).html($('#ccLast').val());
$('#ccjTitle' + currentRow).html($('#ccjTitle').val());
$('#ccEsculation' + currentRow).html($('#ccEsculation').val());
$('#ccMobile' + currentRow).html($('#ccMobile').val());
$('#ccOffice' + currentRow).html($('#ccOffice').val());
$('#ccEmail' + currentRow).html($('#ccEmail').val());
$("#ccFirst,#ccLast,#ccjTitle,#ccEsculation,#ccMobile,#ccOffice,#ccEmail").val("");
currentRow = -1;
}
function deleteRow(rowID) {
$('#row' + rowID).remove();
$('#SummaryRow' + rowID).remove();
var rowCount = parseInt(document.getElementById("ContactsRowCount").value, 10);
rowCount--;
document.getElementById("ContactsRowCount").value = rowCount;
}
function ccClear() {
$("#ccFirst,#ccLast,#ccjTitle,#ccEsculation,#ccMobile,#ccOffice,#ccEmail").val("");
}
Add a validation="regex here" to the input tags first of all to give them an easy visual notification. Beyond if you want to validate with jQuery, you can check each value and not send out an ajax request if any are invalid, using something like this to verify that ( string in this case ) values are correct $(your_element_here).val().match(your_regex_here)
Perhaps an if ($(#id).val().match(some_verification_regex) == null){ return false }
only letters: /^[A-z]+$/
phone number like you mentioned above: /^\(\d{3}\) \d{3}-\d{4}$/
What i would suggest is a validation jQuery plugin and you can find many of them and choose what suites your needs from bellow:
jquery.bassistance
ddarrenjQuery-Live-Form-Validation-For-Twitter-Bootstrap
jzae fferer-jquery-validation
Or you search on jQuery.com site to get many jquery compatible validation plugins.
But if you don't want to use any plugin then you have to write your own validation code.
Email and other fields validation functions:
function emailValidate(e){
var p = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
return p.test(e);
}
function validate(val, min, max){
return (val.length < min || val.length > max?false:true);
}
vfirstName = validate(firstName,1,15);//if between 1 and 15 will return true
vlastName = validate(lastName ,1,15);//if between 1 and 15 will return true
vjobTitle = validate(jobTitle ,1,50);//if between 1 and 15 will return true
veSculation = validate(eSculation ,1,50);//if between 1 and 15 will return true
vmobilePhone = validate(eSculation ,1,50);//if between 1 and 15 will return true
vofficePhone = validate(officePhone,12,12);//because `(999) 999-99999` length is 12
veMail = emailValidate(eMail);//also will return false if wrong email format
if(vfirstName && vlastName && vjobTitle && veSculation && vmobilePhone && vofficePhone && veMail)
var errors = false;
else
var errors = true;
Then before appending the generated row you can add some condition like:
if(!errors){
$("#customerContactSubmitedTable").append(sHtml);
//....rest of your code
}else
alert('please correct the fields');//or any other event