if cell modified data on col1 by appscript? - performance

I want,
If B1 edited/Not empty, put TimeStamp on A1. here is my script-
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 2 ) { //checks the column
var nextCell = s.getRange(r, 1);
if( nextCell.getValue() !== '' ) //is not empty
nextCell.setValue(new Date());
}
}
}
Problem is, getRange(r, 1) which should be getRange(r, -1) as colB=0, colC=1 colA=-1
But putting -1 is not working. How to fix that??

try this...
if(r.getColumn() == 2){
var prevCellValue = r.offset(0,-1).getValue;
if(prevCellValue() !== ''){
r.offset(0,-1).setValue(new Date());
}
}

Related

Why don't checkboxes in my Handsontable Custom Editor toggle?

I'm using the latest Handsontable version 9.0.0 without any framework and I'm trying to follow the Cell editor developer guide, but I'm at a loss.
My requirement is to show a couple of checkboxes and a text box in one cell (not my idea). My thought was to have the data for the cell be a little json string {"Attr1": true, "Attr2": false} and have a custom renderer/editor that would parse the cell value and set the checkboxes appropriately.
I made a fiddle of it here: http://jsfiddle.net/9k1x4z6b/2/
I created a class for the custom attributes column and a renderer function and set the renderer and editor for the column like this
class CustomAttributesEditor extends Handsontable.editors.BaseEditor {
/**
* Initializes editor instance, DOM Element and mount hooks.
*/
// constructor (props) {
// super(props)
// }
prepare(row, col, prop, td, originalValue, cellProperties) {
// Invoke the original method...
super.prepare(row, col, prop, td, originalValue, cellProperties);
td.innerHTML = '';
this.AttributeNames = ['Attr1', 'Attr2'];
this.ctrls = {};
let parsedValue = JSON.parse(Handsontable.helper.stringify(originalValue));
// Create checkbox controls
for (let i = 0; i < this.AttributeNames.length; i++) {
let AttributeName = this.AttributeNames[i];
let span = document.createElement('span');
span.style.whiteSpace = 'nowrap';
let checkbox = document.createElement('input');
this.ctrls[AttributeName] = checkbox;
checkbox.type = 'checkbox';
if (parsedValue[AttributeName] == 'yes') {
checkbox.checked = true;
}
let label = document.createElement('label');
label.innerHTML = AttributeName;
label.htmlFor = checkbox.id;
span.appendChild(checkbox);
span.appendChild(label);
td.appendChild(span);
td.appendChild(document.createElement('br'));
}
// Create a control that is shown/hidden when the "Attr2" checkbox is toggled
let CustomAttributesAttr3SubDiv = document.createElement('div');
var label = document.createElement('label');
label.innerHTML = "Attr3 supplier:";
CustomAttributesAttr3SubDiv.appendChild(label);
var CustomAttributesAttr3 = document.createElement('input');
if (parsedValue.hasOwnProperty('Attr3')) {
CustomAttributesAttr3.value = parsedValue['Attr3'];
}
this.ctrls['Attr3'] = CustomAttributesAttr3;
this.AttributeNames.push('Attr3');
CustomAttributesAttr3.setAttribute('title', 'Attr3');
CustomAttributesAttr3.style.width = '12em';
CustomAttributesAttr3SubDiv.appendChild(CustomAttributesAttr3);
CustomAttributesAttr3SubDiv.appendChild(document.createElement('br'));
td.appendChild(CustomAttributesAttr3SubDiv);
let Attr2Checkbox = this.ctrls['Attr2'];
//CustomAttributes_ShowHideValueCtrl(Attr2Checkbox);
$(Attr2Checkbox).off('change').on('change', function () {
//CustomAttributes_ShowHideValueCtrl(this); // irrelevant to checkbox problem. function shows Attr3 input when Attr2Checkbox is checked, hides otherwise
});
//preventDefault();
}
getValue(){
// This function returns the set value of the controls
let ctrls = this.ctrls;
let resultDict = {};
for (let ctrlID in ctrls){
let ctrl = ctrls[ctrlID];
let FormattedAttributeName = ctrlID.replaceAll(' ', '_');
let val = null;
if (ctrl.type == 'checkbox'){
if (ctrl.checked == true) {
val = 'yes';
} else {
val = null;
}
} else {
val = ctrl.value;
}
resultDict[FormattedAttributeName] = val;
}
return JSON.stringify(resultDict)
}
setValue(value){
// this function sets the value of the controls to match the data value
let parsedValue = {};
try {
parsedValue = JSON.parse(Handsontable.helper.stringify(value));
} catch (exc) {
for (let i = 0; i < this.AttributeNames.length; i++) {
parsedValue[this.AttributeNames[i]] = 'no';
}
}
let ctrls = this.ctrls;
let resultDict = {};
for (let ctrlID in ctrls){
let ctrl = ctrls[ctrlID];
let FormattedAttributeName = ctrlID.replaceAll(' ', '_');
let val = parsedValue[FormattedAttributeName];
if (ctrl.type == 'checkbox'){
if (val == 'yes'){
ctrl.checked = true;
} else {
ctrl.checked = false;
}
} else {
ctrl.value = val;
}
}
}
saveValue(value, ctrlDown){
super.saveValue(value, ctrlDown);
}
open(){}
close(){}
focus(){}
}
function CustomAttributesRenderer(instance, td, row, col, prop, value, cellProperties) {
// This function shows labels for the checked Attr1-3 values
let AttributeNames = ['Attr1', 'Attr2', 'Attr3'];
parsedValue = JSON.parse(Handsontable.helper.stringify(value));
Handsontable.dom.empty(td);
for (let i = 0; i < AttributeNames.length; i++) {
let AttributeName = AttributeNames[i];
let span = document.createElement('span');
span.style.whiteSpace = 'nowrap';
if (parsedValue[AttributeName] == 'yes') {
let label = document.createElement('label');
label.innerHTML = AttributeName;
span.appendChild(label);
td.appendChild(span);
}
td.appendChild(document.createElement('br'));
}
return td;
}
document.addEventListener("DOMContentLoaded", function () {
var container = document.getElementById('divBFEPartMatrix');
var hot = new Handsontable(container, {
data: [
[JSON.stringify({"Attr1": "yes", "Attr2": "yes", "Attr3": ""})],
[JSON.stringify({"Attr1": "yes", "Attr2": "yes", "Attr3": "somevalue"})],
[JSON.stringify({"Attr1": "no", "Attr2": "no", "Attr3": ""})],
],
columns: [
{renderer: CustomAttributesRenderer, editor: CustomAttributesEditor}
],
rowHeaders: true,
colHeaders: true,
filters: true,
dropdownMenu: true
});
})
The result appears properly, with the cell initially not having checkboxes visible due to the renderer not showing them, then when you click the cell the checkboxes appear. The problem is when you click the checkbox it doesn't toggle.
I presume something in handsontable is re-creating the td and blowing away the state change, but I can't figure out how to prevent that from happening. Is there a fully working custom editor fiddle or something I can reference to figure out how to prevent bubbling?
Any help you can offer would be greatly appreciated.
Well, after another couple days of fiddling around I figured out the full set of code I needed to add to make this work. Posted here in case it helps someone else trying to make a custom cell editor/renderer in handsontable.
class SubstitutePartEditor extends Handsontable.editors.BaseEditor {
init(){
// This function creates the edit div
let div = document.createElement('div');
this.div = div;
div.style.display = 'none';
div.style.position = 'absolute';
div.style.width = 'auto';
div.style.backgroundColor = 'white';
this.AttributeNames = ['The waste bin is part of the waste cart', 'This item includes SUPPLIER tapestry'];
this.ctrls = {};
let cbIsSubstitutePart = document.createElement('input');
this.ctrls['IsSubstitutePart'] = cbIsSubstitutePart;
cbIsSubstitutePart.type = 'checkbox';
div.appendChild(cbIsSubstitutePart);
div.appendChild(document.createElement('br'));
let SubstitutePartSubDiv = document.createElement('div');
SubstitutePartSubDiv.style.display = 'inline-block';
div.appendChild(SubstitutePartSubDiv);
let inputSubstitutePart = document.createElement('textarea');
this.ctrls['SubstitutePart'] = inputSubstitutePart;
inputSubstitutePart.style.width = '220px';
inputSubstitutePart.style.height = '88px';
SubstitutePartSubDiv.appendChild(inputSubstitutePart);
this.hot.rootElement.appendChild(div);
}
UpdateDependentControls(){
let RequiredCtrl = this.ctrls['IsSubstitutePart'];
let Ctrl = this.ctrls['SubstitutePart'];
if (RequiredCtrl.checked == true){
Ctrl.style.display = '';
} else {
Ctrl.style.display = 'none';
}
$(RequiredCtrl).off('change').on('change', function(){
if (RequiredCtrl.checked == true){
Ctrl.style.display = '';
} else {
Ctrl.style.display = 'none';
}
});
}
getValue(){
// This function returns the set value of the controls
let ctrls = this.ctrls;
let resultDict = {};
for (let ctrlID in ctrls){
let ctrl = ctrls[ctrlID];
let FormattedAttributeName = ctrlID.replaceAll(' ', '_');
let val = null;
if (ctrl.type == 'checkbox'){
if (ctrl.checked == true) {
val = 'yes';
} else {
val = null;
}
} else {
val = ctrl.value;
}
resultDict[FormattedAttributeName] = val;
}
return JSON.stringify(resultDict)
}
setValue(value){
// this function sets the value of the controls to match the data value
let parsedValue = {};
try {
parsedValue = JSON.parse(Handsontable.helper.stringify(value));
} catch (exc) {
parsedValue = {
IsSubstitutePart: 'no',
SubstitutePart: "This item requires a waiver from the operator's foreign regulatory agency, <FOREIGN REGULATORY AGENCY NAME>."
};
}
let ctrls = this.ctrls;
let resultDict = {};
for (let ctrlID in ctrls){
let ctrl = ctrls[ctrlID];
let FormattedAttributeName = ctrlID.replaceAll(' ', '_');
let val = parsedValue[FormattedAttributeName];
if (ctrl.type == 'checkbox'){
if (val == 'yes'){
ctrl.checked = true;
} else {
ctrl.checked = false;
}
} else {
ctrl.value = val;
}
}
}
saveValue(value, ctrlDown){
super.saveValue(value, ctrlDown);
}
open() {
this._opened = true;
this.refreshDimensions();
this.UpdateDependentControls();
this.div.style.display = '';
}
refreshDimensions() {
this.TD = this.getEditedCell();
// TD is outside of the viewport.
if (!this.TD) {
this.close();
return;
}
const { wtOverlays } = this.hot.view.wt;
const currentOffset = Handsontable.dom.offset(this.TD);
const containerOffset = Handsontable.dom.offset(this.hot.rootElement);
const scrollableContainer = wtOverlays.scrollableElement;
const editorSection = this.checkEditorSection();
let width = Handsontable.dom.outerWidth(this.TD) + 1;
let height = Handsontable.dom.outerHeight(this.TD) + 1;
let editTop = currentOffset.top - containerOffset.top - 1 - (scrollableContainer.scrollTop || 0);
let editLeft = currentOffset.left - containerOffset.left - 1 - (scrollableContainer.scrollLeft || 0);
let cssTransformOffset;
switch (editorSection) {
case 'top':
cssTransformOffset = Handsontable.dom.getCssTransform(wtOverlays.topOverlay.clone.wtTable.holder.parentNode);
break;
case 'left':
cssTransformOffset = Handsontable.dom.getCssTransform(wtOverlays.leftOverlay.clone.wtTable.holder.parentNode);
break;
case 'top-left-corner':
cssTransformOffset = Handsontable.dom.getCssTransform(wtOverlays.topLeftCornerOverlay.clone.wtTable.holder.parentNode);
break;
case 'bottom-left-corner':
cssTransformOffset = Handsontable.dom.getCssTransform(wtOverlays.bottomLeftCornerOverlay.clone.wtTable.holder.parentNode);
break;
case 'bottom':
cssTransformOffset = Handsontable.dom.getCssTransform(wtOverlays.bottomOverlay.clone.wtTable.holder.parentNode);
break;
default:
break;
}
if (this.hot.getSelectedLast()[0] === 0) {
editTop += 1;
}
if (this.hot.getSelectedLast()[1] === 0) {
editLeft += 1;
}
const selectStyle = this.div.style;
if (cssTransformOffset && cssTransformOffset !== -1) {
selectStyle[cssTransformOffset[0]] = cssTransformOffset[1];
} else {
Handsontable.dom.resetCssTransform(this.div);
}
const cellComputedStyle = Handsontable.dom.getComputedStyle(this.TD, this.hot.rootWindow);
if (parseInt(cellComputedStyle.borderTopWidth, 10) > 0) {
height -= 1;
}
if (parseInt(cellComputedStyle.borderLeftWidth, 10) > 0) {
width -= 1;
}
selectStyle.height = `${height}px`;
selectStyle.minWidth = `${width}px`;
selectStyle.top = `${editTop}px`;
selectStyle.left = `${editLeft}px`;
selectStyle.margin = '0px';
}
getEditedCell() {
const { wtOverlays } = this.hot.view.wt;
const editorSection = this.checkEditorSection();
let editedCell;
switch (editorSection) {
case 'top':
editedCell = wtOverlays.topOverlay.clone.wtTable.getCell({
row: this.row,
col: this.col
});
this.select.style.zIndex = 101;
break;
case 'corner':
editedCell = wtOverlays.topLeftCornerOverlay.clone.wtTable.getCell({
row: this.row,
col: this.col
});
this.select.style.zIndex = 103;
break;
case 'left':
editedCell = wtOverlays.leftOverlay.clone.wtTable.getCell({
row: this.row,
col: this.col
});
this.select.style.zIndex = 102;
break;
default:
editedCell = this.hot.getCell(this.row, this.col);
this.div.style.zIndex = '';
break;
}
return editedCell < 0 ? void 0 : editedCell;
}
focus() {
this.div.focus();
}
close() {
this._opened = false;
this.div.style.display = 'none';
}
}
function SubstitutePartRenderer(instance, td, row, col, prop, value, cellProperties) {
// This function draws the multi checkboxes for the SubstitutePart input field
// Note: if AttributeNames changes you must also update BFEPartMatrix_Edit.ascx line ~240 to match (<- this is where the data is saved)
//Handsontable.renderers.HtmlRenderer.apply(this, arguments);
let parsedValue = {};
try {
parsedValue = JSON.parse(Handsontable.helper.stringify(value));
} catch {
// nothing to do
}
Handsontable.dom.empty(td);
let div = document.createElement('div');
//div.style.whiteSpace = 'nowrap';
div.style.display = 'block';
td.appendChild(div);
if (parsedValue.hasOwnProperty('IsSubstitutePart')) {
if (parsedValue.IsSubstitutePart == 'yes') {
} else {
td.innerHTML = 'N/A';
return;
}
} else {
td.innerHTML = 'N/A';
return;
}
let SubstitutePartSubDiv = document.createElement('div');
SubstitutePartSubDiv.style.display = 'inline-block';
div.appendChild(SubstitutePartSubDiv);
// text area
let inputSubstitutePart = document.createElement('label');
inputSubstitutePart.innerHTML = parsedValue['SubstitutePart'].escape();
inputSubstitutePart.style.width = '220px';
inputSubstitutePart.style.height = '88px';
SubstitutePartSubDiv.appendChild(inputSubstitutePart);
return td;
}
then set the render and editor of the hot column like this
columns: [
{renderer: CustomAttributesRenderer, editor: CustomAttributesEditor}
],

Vue JS - how can I call may data in my filter function of javascript

In our application, I added a validation of each row that you can't have 2 same columns values. I'm done with it but Im having a problem in delete row
Example
There is a delete button in the right side when I clicked it, it gives me an error Cannot read property ..... even tho it is already declared in my data
Error Message
Vue code
deleteRow(i, e){
var month = this.added_items[i].selected_month.id
var chart_of_account_id = this.added_items[i].selected_chart_of_account.id
var count = 0
// var duplicate = false
this.submitStatus = ''
this.duplicate_month = false
this.added_items.filter(function( obj ) {
console.log(this.submitStatus)
if((obj.selected_month.id == month && obj.selected_chart_of_account.id == chart_of_account_id) && obj.id != i){
count++
if(count >= 2)
{
// this.added_items[i].duplicate_month = true
// this.submitStatus = 'ERROR'
// this.duplicate_month = true
}
}
return obj.id !== i;
});
console.log(this.added_items)
e.preventDefault()
},
Question: How can I call my data inside of my filter function? because when I tried any of these: this.submitStatus/this.added_items[i].duplicate_month/this.duplicate_month it gives me an error
You can approach it in two ways
Option 1: Arrow Functions
this.added_items.filter(( obj ) => {
console.log(this.submitStatus)
if(
(
obj.selected_month.id == month &&
obj.selected_chart_of_account.id == chart_of_account_id
) &&
obj.id != i
){
count++
if(count >= 2)
{
// this.added_items[i].duplicate_month = true
// this.submitStatus = 'ERROR'
// this.duplicate_month = true
}
}
return obj.id !== i;
});
Option 2: Bind this
this.added_items.filter(function( obj ) {
console.log(this.submitStatus)
if(
(
obj.selected_month.id == month &&
obj.selected_chart_of_account.id == chart_of_account_id
) &&
obj.id != i
){
count++
if(count >= 2)
{
// this.added_items[i].duplicate_month = true
// this.submitStatus = 'ERROR'
// this.duplicate_month = true
}
}
return obj.id !== i;
}).bind(this);

Do you suggest a script that shows a random comment of my blog, created with bloggers?

good evening.
Do you suggest a script that shows a random comment of my blog, created with bloggers?
thank you
That should be possible to generate using the global comment feed provided by Blogger -
http://blogname.blogspot.com/feeds/comments/default
A working snippet for the same would look like -
<div id='stylify_random_comments'></div>
<script style='text/javascript'>
//<![CDATA[
var commentTitleOriginal, myLink, myDiv, myImage;
var main;
function getcomment(json) {
var s;
var entry = json.feed.entry[0];
var commentTitle = entry.title.$t;
commentTitleOriginal = commentTitle;
if (isNaN(titleLength) || titleLength == 0) {
commentTitle = '';
} else if (commentTitle.length > titleLength) commentTitle = commentTitle.substring(0, titleLength) + "...";
var commentUrl;
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') {
commentUrl = entry.link[k].href;
break;
}
}
if (showThumbs == true) {
var thumbUrl = "";
try {
thumbUrl = entry.author["0"].gd$image.src;
if (imgDim == "80" || imgDim == "85" || imgDim == "90" || imgDim == "95" || imgDim == "100") thumbUrl = thumbUrl.replace("/s72-c/", "/s104-c/");
} catch (error) {
if ("content" in entry) s = entry.content.$t;
else s = "";
if (thumbUrl == "" && mediaThumbsOnly == false) {
a = s.indexOf("<img");
b = s.indexOf("src=\"", a);
c = s.indexOf("\"", b + 5);
d = s.substr(b + 5, c - b - 5);
if ((a != -1) && (b != -1) && (c != -1) && (d != "")) thumbUrl = d;
}
}
if (thumbUrl == "" && showNoImage == true) thumbUrl = 'http://1.bp.blogspot.com/_u4gySN2ZgqE/SosvnavWq0I/AAAAAAAAArk/yL95WlyTqr0/s400/noimage.png';
} //end ifcommenthumbs
if (showcommentDate == true) {
var commentdate = entry.published.$t;
var cdyear = commentdate.substring(0, 4);
var cdmonth = commentdate.substring(5, 7);
var cdday = commentdate.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";
} //end if date
code = "";
main = document.getElementById('stylify_random_comments');
myDiv = document.createElement('div');
myDiv.setAttribute("class", "stylify_item_title");
myDiv.style.clear = "both";
myDiv.style.marginTop = "4px";
myLink = createLink(commentUrl, "_top", commentTitleOriginal)
if (commentTitle != '') myDiv.appendChild(myLink);
main.appendChild(myDiv);
if (commentTitle != '') myLink.innerHTML = commentTitle;
if (showThumbs == true && thumbUrl != "") {
myImage = document.createElement('img');
myImage.style.border = "0px solid transparent";
myImage.style.margin = "5px";
myImage.style.boxShadow = "0 0 0px rgba(0, 0, 0, 0.3)";
myImage.setAttribute("src", thumbUrl);
myImage.style.cssFloat = imgFloat;
myImage.style.styleFloat = imgFloat;
//myImage.setAttribute("alt", commentTitleOriginal);
myImage.setAttribute("width", imgDim);
//myImage.setAttribute("align", imgFloat);
myImage.setAttribute("height", imgDim);
myLink = document.createElement('a');
myLink.setAttribute("href", commentUrl + "?utm_source=blog&utm_medium=gadget&utm_campaign=stylify_random_comments");
myLink.setAttribute("target", "_top");
myLink.setAttribute("title", commentTitleOriginal);
myLink.appendChild(myImage);
myDiv = document.createElement('div');
myDiv.setAttribute("class", "stylify_item_thumb");
myDiv.appendChild(myLink);
main.appendChild(myDiv);
}
try {
if ("content" in entry) {
var commentContent = entry.content.$t;
} else if ("summary" in entry) {
var commentContent = entry.summary.$t;
} else var commentContent = "";
var re = /<\S[^>]*>/g;
commentContent = commentContent.replace(re, "");
if (showSummary == true) {
myDiv = createDiv("stylify_item_summary");
if (commentContent.length < summaryLength) {
myDiv.innerHTML = commentContent;
} else {
commentContent = commentContent.substring(0, summaryLength);
var quoteEnd = commentContent.lastIndexOf(" ");
commentContent = commentContent.substring(0, quoteEnd);
myDiv.innerHTML = commentContent + '...';
}
main.appendChild(myDiv);
}
} //end try
catch (error) {}
myDiv = createDiv("stylify_item_meta");
myDiv.style.clear = "both";
myDiv.style.marginBottom = "4px";
var flag = 0;
if (showcommentDate == true) {
myDiv.appendChild(document.createTextNode(monthnames[parseInt(cdmonth, 10)] + '-' + cdday + '-' + cdyear));
flag = 1;
}
if (showCommentCount == true) {
if (flag == 1) {
myDiv.appendChild(document.createTextNode(" | "));
}
if (commentText == '1 Comments') commentText = '1 Comment';
if (commentText == '0 Comments') commentText = 'No Comments';
var myLink = createLink(commentUrl, "_top", commentText + " on " + commentTitleOriginal)
myDiv.appendChild(myLink);
myLink.innerHTML = commentText;
flag = 1;;
}
if (showReadMore == true) {
if (flag == 1) {
myDiv.appendChild(document.createTextNode(" | "));
}
var myLink = createLink(commentUrl, "_top", commentTitleOriginal)
myDiv.appendChild(myLink);
myLink.innerHTML = readMore + " ยป";
flag = 1;;
}
if (flag == 1 || showSummary || commentTitle != "") main.appendChild(myDiv);
}
function getRandom(json) {
var feedUrl = '/feeds/comments/default';
if (mediaThumbsOnly || !showThumbs) feedUrl = feedUrl.replace("comments/default", "comments/summary");
totalcomments = parseInt(json.feed.openSearch$totalResults.$t);
var rand = [];
if (numberOfcomments > totalcomments) numberOfcomments = totalcomments;
if (numberOfcomments > 15) numberOfcomments = 15;
while (rand.length < numberOfcomments) {
var randomNumber = Math.ceil(Math.random() * totalcomments);
var found = false;
for (var i = 0; i < rand.length; i++) {
if (rand[i] == randomNumber) {
found = true;
break;
}
}
if (!found) rand[rand.length] = randomNumber;
}
var head = document.getElementsByTagName("head")[0] || document.documentElement;
for (var i = 0; i < rand.length; i++) {
script = document.createElement("script");
script.src = feedUrl + "?start-index=" + rand[i] + "&max-results=1&alt=json-in-script&callback=getcomment";
script.charSet = "utf-8";
head.appendChild(script);
}
}
function createDiv(className) {
var myDiv = document.createElement('div');
myDiv.setAttribute("class", className);
return myDiv;
}
function createLink(href, target, title) {
var myLink = document.createElement('a');
if (href.indexOf("?utm_source=") == -1) href = href + "?utm_source=blog&utm_medium=gadget&utm_campaign=stylify_random_comments";
myLink.setAttribute("href", href);
myLink.setAttribute("target", target);
myLink.setAttribute("title", title);
return myLink;
}
//]]>
</script>
<script style='text/javascript'>
var numberOfcomments = 5;
var showcommentDate = false;
var showSummary = true;
var summaryLength = 200;
var titleLength = 100;
var showCommentCount = false;
var showThumbs = true;
var showNoImage = false;
var imgDim = 50;
var imgFloat = 'left';
var myMargin = 0;
var mediaThumbsOnly = true;
var showReadMore = false;
var readMore = 'More';
</script>
<script src='/feeds/comments/default?max-results=1&alt=json-in-script&callback=getRandom'></script>

Calling existing method to create new instances

Need direction on how to code for the three instances to then assign values to the variables using isWarmBlooded method ..
```Animal.prototype.isWarmBlooded = function(species){
if(this.species === "Fish"){
return this.species = false;
}
if(this.species === "Monkey" || this.species === "Bird"){
return this.species = true;
}
if(this.species !== "Fish" || this.species !== "Monkey" || this.species !== "Bird"){
return "Could not determine if warm-blooded";
}
};
//Call the isWarmBlooded method on three Animal instances
//and assign the values to each variable below.
var warmBloodedAnimal = Animal.prototype.isWarmBlooded("Monkey");
var coldBloodedAnimal;
var notWarmOrColdAnimal;```
var Animal = function (species){
this.species = species;
};
Animal.prototype.isWarmBlooded = function(species){
if (this.species === "Fish"){
return false;
}
else if(this.species === "Monkey" || this.species === "Bird"){
return true;
}
else{
return "Could not determine if warm-blooded";
}
};
var warmBloodedAnimal = new Animal("Monkey");
console.log(warmBloodedAnimal.isWarmBlooded());

jQuery Validate plugin. How to check if any of fields is filled in

How to check if any of 4 fields I have is filled in? If any of them is filled in, then it's fine, if not, it's not.
$("#sendMsg").click(function(){
var name = $("#name").val();
var email = $("#email").val();
var subject = $("#subject").val();
var message = $("#message").val();
if(name == ""){
$("#errorMsg").show();
return false;
}
if(email == ""){
$("#errorMsg").show();
return false;
}
if(subject == ""){
$("#errorMsg2").show();
return false;
}
if(message == ""){
$("#errorMsg3").show();
return false;
}
});
if (document.getElementById("idfield1") === undefined)
{
// do noting
}
else
{
// do something
}

Resources