Hello everyone)) I have problem with moving value inside th function, please help me
First I have field "allValid" - has taken boolean value "true".
Next I did 3 checking breakpoints in script where this field must change boolean value on "false".
But whatever i do allValid always has "true". I cant understand what am I doing wrong.
function ButtonClickAction(){
let allValid = true;
var UserInfo = {};
UserInfo.zLOGIN = document.getElementById("LOGIN").value;
UserInfo.zSSCC = document.getElementById("SSCC").value;
UserInfo.zPLACE = document.getElementById("PLACE").value;
var toValidate = {
LOGIN: "LOGIN REQUIRED",
SSCC: "SSCC REQUIRED",
PLACE: "PLACE REQUIRED"
}
var idKeys = Object.keys(toValidate);
//first checking
idKeys.forEach(function(id){
isValid = checkIfValid(id,toValidate[id]);
allValid = isValid;
});
//second checking
google.script.run.withSuccessHandler(onLOGIN).searchLogins(UserInfo);
function onLOGIN(findLogin) {
if (!findLogin) {
alert("LOGIN NOT EXIST");
allValid = false;
}
}
//thirdchecking
console.log(allValid);
google.script.run.withSuccessHandler(onSSCC).searchSSCC(UserInfo);
function onSSCC(findSSCC) {
if (!findSSCC) {
alert("SSCC NOT EXIST");
allValid = false;
}
}
//finish result
if (!allValid){
alert("YOU HAVE NOTHING");
}
else {
addRecord(idElem);
}
}
function checkIfValid(elId, message){
var isValid = document.getElementById(elId).checkValidity();
if(!isValid){
alert(message);
return false;
}
return true;
}
At the end of the function "ButtonClickAction" I have "finish result", but it works wrong because allValid has always "true". Help!
(sorry for bad English, it's my non-native language, I try explain correctly)
... and some server code:
var url = "https://docs.google.com/spreadsheets/d/1s8l-8N8dI-GGJi_mmYs2f_88VBcnzWfv3YHgk1HvIh0/edit?usp=sharing";
var sprSRCH = SpreadsheetApp.openByUrl(url);
let sheetSRCHSSCC = sprSRCH.getSheetByName("PUTAWAY_TO");
let sheetTSD = sprSRCH.getSheetByName("ПРИВЯЗКА МЕСТ");
function searchLogins(UserInfo){
let sheetSRCHLGN = sprSRCH.getSheetByName("ЛОГИНЫ");
let findingRLGN = sheetSRCHLGN.getRange("A:A").getValues();
let valToFind = UserInfo.zLOGIN;
for (let i = 0; i < findingRLGN.length; i++){
if(findingRLGN[i].indexOf(valToFind)!==-1){
return true;
}
};
return false;
}
function searchSSCC(UserInfo){
let findingRSSCC = sheetSRCHSSCC.getRange("M:M").getValues();
let valToFind = UserInfo.zSSCС;
for (let i = 0; i < findingRSSCC.length; i++){
if(findingRSSCC[i].indexOf(valToFind)!==-1){
return true;
break;
}
};
indx=2;
return false;
}
Related
I have a situation where I need to determine if an object is empty or not. I cannot figure out the if statement to make this work.
function test_isObjectEmpty(){
var responces = {};
// var responces = {'test':'test'};
var result = "";
if (responces == {}){ // this does not work
result ="Nothing found";
} else {
result ="Responce found";
}
Logger.log(result)
}
You can check the objects length, if 0, it's empty:
var obj = {};
if (Object.getOwnPropertyNames(obj).length === 0) {
//it's empty
}
else {
//it's not empty
}
I'm having problems displaying my Haxe game in IE9. It's actually not displaying at all. We tracked down the issue inside the compiled JS file for Haxe and found out that the problem is within the haxe.HTTP API.
There are certain things that need to be checked and done for IE9 to work with xmlhttprequests. These things were not done in the Haxe API.
This is the http class without my fix:
this.url = url;
this.headers = new List();
this.params = new List();
this.async = true;
};
$hxClasses["haxe.Http"] = haxe.Http;
haxe.Http.__name__ = ["haxe","Http"];
haxe.Http.prototype = {
setParameter: function(param,value) {
this.params = Lambda.filter(this.params,function(p) {
return p.param != param;
});
this.params.push({ param : param, value : value});
return this;
}
,request: function(post) {
var me = this;
me.responseData = null;
var r = this.req = js.Browser.createXMLHttpRequest();
var onreadystatechange = function(_) {
if(r.readyState != 4) return;
var s;
try {
s = r.status;
} catch( e ) {
s = null;
}
if(s == undefined) s = null;
if(s != null) me.onStatus(s);
if(s != null && s >= 200 && s < 400) {
me.req = null;
me.onData(me.responseData = r.responseText);
} else if(s == null) {
me.req = null;
me.onError("Failed to connect or resolve host");
} else switch(s) {
case 12029:
me.req = null;
me.onError("Failed to connect to host");
break;
case 12007:
me.req = null;
me.onError("Unknown host");
break;
default:
me.req = null;
me.responseData = r.responseText;
me.onError("Http Error #" + r.status);
}
};
if(this.async) r.onreadystatechange = onreadystatechange;
var uri = this.postData;
if(uri != null) post = true; else {
var $it0 = this.params.iterator();
while( $it0.hasNext() ) {
var p = $it0.next();
if(uri == null) uri = ""; else uri += "&";
uri += encodeURIComponent(p.param) + "=" + encodeURIComponent(p.value);
}
}
try {
if(post) r.open("POST",this.url,this.async); else if(uri != null) {
var question = this.url.split("?").length <= 1;
r.open("GET",this.url + (question?"?":"&") + uri,this.async);
uri = null;
} else r.open("GET",this.url,this.async);
} catch( e1 ) {
me.req = null;
this.onError(e1.toString());
return;
}
if(!Lambda.exists(this.headers,function(h) {
return h.header == "Content-Type";
}) && post && this.postData == null) r.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
var $it1 = this.headers.iterator();
while( $it1.hasNext() ) {
var h1 = $it1.next();
r.setRequestHeader(h1.header,h1.value);
}
r.send(uri);
if(!this.async) onreadystatechange(null);
}
,onData: function(data) {
}
,onError: function(msg) {
}
,onStatus: function(status) {
}
,__class__: haxe.Http
};
and this is the code WITH the fix:
haxe.Http = function(url) {
this.url = url;
this.headers = new List();
this.params = new List();
this.async = true;
};
$hxClasses["haxe.Http"] = haxe.Http;
haxe.Http.__name__ = ["haxe","Http"];
haxe.Http.prototype = {
setParameter: function(param,value) {
this.params = Lambda.filter(this.params,function(p) {
return p.param != param;
});
this.params.push({ param : param, value : value});
return this;
}
,request: function(post) {
var me = this;
me.responseData = null;
var r = this.req = js.Browser.createXMLHttpRequest();
var onreadystatechange = function(_) {
console.log('in onreadystatechange function');
//if(r.readyState != 4) return;
console.log(r.responseText);
console.log('r.status: ' + r.status);
me.req = null;
me.onData(me.responseData = r.responseText);
};
if(typeof XDomainRequest != "undefined") {
console.log('XDomainRequest');
r.onload = onreadystatechange;
}
var uri = this.postData;
try {
console.log('calling r.open with url: ' + this.url);
r.open("GET",this.url);
} catch( e1 ) {
me.req = null;
this.onError(e1.toString());
return;
}
//r.send(uri);
//do it, wrapped in timeout to fix ie9
setTimeout(function () {
r.send();
}, 0);
//if(!this.async) onreadystatechange(null);
}
,onData: function(data) {
}
,onError: function(msg) {
}
,onStatus: function(status) {
}
,__class__: haxe.Http
};
Note that this only implements the IE9 fix without doing the if statements to keep support for other browsers. But it's really easy. the IF statement is simply
if(typeof XDomainRequest != "undefined") return new XDomainRequest();
Basically, I know what the issue is, I just have no idea how I can change these things within the core of Haxe itself.
Thanks.
https://github.com/HaxeFoundation/haxe/pull/3449
BAM! Got it working in a local version of my haxe. Fixed for all browsers and sent a pull request. :D
Good job on this one!
You have to contact the Haxe mailing list directly, most thinking heads are over there rather than here :)
https://groups.google.com/d/forum/haxelang
/* Problem description- I am using json stringify method to convert an javascript array to string in json notation.However I get an error message that 'Object property or method not supported' at line
hidden.value = JSON.stringify(jsonObj);
This should work as stringify is supported in IE8.Please advise
Full code below */
function getgridvalue() {
var exportLicenseId;
var bolGrossQuantity;
var bolNetQuantity;
var totalBolGrossQty =0 ;
var totalBolNetQty =0;
var jsonObj = []; //declare array
var netQtyTextBoxValue = Number(document.getElementById("<%= txtNetQty.ClientID %>").value);
var atLeastOneChecked = false;
var gridview = document.getElementById("<%= ExporterGrid.ClientID %>"); //Grab a reference to the Grid
for (i = 1; i < gridview.rows.length; i++) //Iterate through the rows
{
if (gridview.rows[i].cells[0].getElementsByTagName("input")[0] != null && gridview.rows[i].cells[0].getElementsByTagName("input")[0].type == "checkbox")
{
if (gridview.rows[i].cells[0].getElementsByTagName("input")[0].checked)
{
atLeastOneChecked = true;
exportLicenseId = gridview.rows[i].cells[8].getElementsByTagName("input")[0].value;
bolNetQuantity = gridview.rows[i].cells[5].getElementsByTagName("input")[0].value;
if (bolNetQuantity == "") {
alert('<%= NetQuantityMandatory %>');
return false;
}
if (!isNumber(bolNetQuantity)) {
alert('<%= NetQuantityNumber %>');
return false;
}
totalBolNetQty += Number(bolNetQuantity);
jsonObj.push({ ExportLicenseId: Number(exportLicenseId), BolNetQuantity: Number(bolNetQuantity) });
}
}
}
if (gridview.rows.length > 2 && !atLeastOneChecked)
{
alert('<%= SelectMsg %>');
return false;
}
if (totalBolNetQty != 0 && netQtyTextBoxValue != totalBolNetQty)
{
alert('<%= NetQuantitySum %>');
return false;
}
var hidden = document.getElementById('HTMLHiddenField');
// if (!this.JSON) {
// this.JSON = {};
// }
var JSON = JSON || {};
if (hidden != null) {
hidden.value = JSON.stringify(jsonObj);
}
}
Use the F12 Developer Tools to check the browser mode. The JSON object exists, but has no methods in IE7 mode. Use the json2 library as a fallback.
json2.js
function makeABox(e):void {
if (e.name == "seri1"){
var newBox:karo1 = new karo1();
}else if(e.name == "seri2"){
var newBox:karo2 = new karo2();
}else{
var newBox:zemin1 = new zemin1();
}
ust_bar.addChild(newBox);
newBox.x = i*60;
newBox.y = s*60;
}
Dee, you should make a question. I'm presuming you got problems with 'namespaces'. Try to define de variable first, with a superclass type, then in those conditionals just give a value. Like this:
function makeABox(e):void {
var newBox:somesuperclass;
if (e.name == "seri1") {
newBox = new karo1();
} else if (e.name == "seri2") {
newBox = new karo2();
} else {
newBox = new zemin1();
}
ust_bar.addChild(newBox);
newBox.x = i*60;
newBox.y = s*60;
}
This is actionsscript3? If is, you probably need e.currentTarget.name.
Hope this helps.
<script type = "text/javascript">
var First_Array = new Array();
function reset_Form2() {document.extraInfo.reset();}
function showList1() {document.getElementById("favSports").style.visibility="visible";}
function showList2() {document.getElementById("favSubjects").style.visibility="visible";}
function hideProceed() {document.getElementById('proceed').style.visibility='hidden';}
function proceedToSecond ()
{
document.getElementById("div1").style.visibility="hidden";
document.getElementById("div2").style.visibility="visible";
document.getElementById("favSports").style.visibility="hidden";
document.getElementById("favSubjects").style.visibility="hidden";
}
function backToFirst () {
document.getElementById("div1").style.visibility="visible";
document.getElementById("div2").style.visibility="hidden";
document.getElementById("favSports").style.visibility="visible";
document.getElementById("favSubjects").style.visibility="visible";
}
function reset_Form(){
document.personalInfo.reset();
document.getElementById("favSports").style.visibility="hidden";
document.getElementById("favSubjects").style.visibility="hidden";
}
function isValidName(firstStr) {
var firstPat = /^([a-zA-Z]+)$/;
var matchArray = firstStr.match(firstPat);
if (matchArray == null) {
alert("That's a weird name, try again");
return false;
}
return true;
}
function isValidZip(zipStr) {
var zipPat =/[0-9]{5}/;
var matchArray = zipStr.match(zipPat);
if(matchArray == null) {
alert("Zip is not in valid format");
return false;
}
return true;
}
function isValidApt(aptStr) {
var aptPat = /[\d]/;
var matchArray = aptStr.match(aptPat);
if(matchArray == null) {
if (aptStr=="") {
return true;
}
alert("Apt is not proper format");
return false;
}
return true;
}
function isValidDate(dateStr) {
//requires 4 digit year:
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
var matchArray = dateStr.match(datePat);
if (matchArray == null) {
alert("Date is not in a valid format.");
return false;
}
return true;
}
function checkRadioFirst() {
var rb = document.personalInfo.salutation;
for(var i=0;i<rb.length;i++) {
if(rb[i].checked) {
return true;
}
}
alert("Please specify a salutation");
return false;
}
function checkCheckFirst() {
var rb = document.personalInfo.operatingSystems;
for(var i=0;i<rb.length;i++) {
if(rb[i].checked) {
return true;
}
}
alert("Please specify an operating system") ;
return false;
}
function checkSelectFirst() {
if ( document.personalInfo.sports.selectedIndex == -1)
{
alert ( "Please select a sport" );
return false;
}
return true;
}
function checkRadioSecond() {
var rb = document.extraInfo.referral;
for(var i=0;i<rb.length;i++) {
if(rb[i].checked) {
return true;
}
}
alert("Please select form of referral");
return false;
}
function checkCheckSecond() {
var rb = document.extraInfo.officeSupplies;
for(var i=0;i<rb.length;i++) {
if(rb[i].checked) {
return true;
}
}
alert("Please select an office supply option");
return false;
}
function checkSelectSecond() {
if ( document.extraInfo.colorPick.selectedIndex == 0 ) {
alert ( "Please select a favorite color" );
return false;
}
return true;
}
function check_Form(){
var retvalue = isValidDate(document.personalInfo.date.value);
if(retvalue) {
retvalue = isValidZip(document.personalInfo.zipCode.value);
if(retvalue) {
retvalue = isValidName(document.personalInfo.nameFirst.value);
if(retvalue) {
retvalue = checkRadioFirst();
if(retvalue) {
retvalue = checkCheckFirst();
if(retvalue) {
retvalue = checkSelectFirst();
if(retvalue) {
retvalue = isValidApt(document.personalInfo.aptNum.value);
if(retvalue){
document.getElementById('proceed').style.visibility='visible';
var rb = document.personalInfo.salutation;
for(var i=0;i<rb.length;i++) {
if(rb[i].checked) {
var salForm = rb[i].value;
}
}
var SportsOptions = "";
for(var j=0;j<document.personalInfo.sports.length;j++){
if ( document.personalInfo.sports.options[j].selected){
SportsOptions += document.personalInfo.sports.options[j].value + " ";
}
}
var SubjectsOptions= "";
for(var k=0;k<document.personalInfo.subjects.length;k++){
if ( document.personalInfo.subjects.options[k].selected){
SubjectsOptions += document.personalInfo.subjects.options[k].value + " ";
}
}
var osBox = document.personalInfo.operatingSystems;
var OSOptions = "";
for(var y=0;y<osBox.length;y++) {
if(osBox[y].checked) {
OSOptions += osBox[y].value + " ";
}
}
First_Array[0] = salForm;
First_Array[1] = document.personalInfo.nameFirst.value;
First_Array[2] = document.personalInfo.nameMiddle.value;
First_Array[3] = document.personalInfo.nameLast.value;
First_Array[4] = document.personalInfo.address.value;
First_Array[5] = document.personalInfo.aptNum.value;
First_Array[6] = document.personalInfo.city.value;
for(var l=0; l<document.personalInfo.state.length; l++) {
if (document.personalInfo.state.options[l].selected) {
First_Array[7] = document.personalInfo.state[l].value;
}
}
First_Array[8] = document.personalInfo.zipCode.value;
First_Array[9] = document.personalInfo.date.value;
First_Array[10] = document.personalInfo.phone.value;
First_Array[11] = SportsOptions;
First_Array[12] = SubjectsOptions;
First_Array[13] = OSOptions;
alert("Everything looks good.");
document.getElementById('validityButton').style.visibility='hidden';
}
}
}
}
}
}
}
}
/*function formAction2() {
var retvalue;
retvalue = checkRadioSecond();
if(!retvalue) {
return retvalue;
}
retvalue = checkCheckSecond();
if(!retvalue) {
return retvalue;
}
return checkSelectSecond() ;
} */
</script>
This is just a sample of the code, there are alot more functions, but I thought the error might be related to surrounding code. I have absolutely no idea why, as I know all the surrounding functions execute, and First_Array is populated.
However when I click the Proceed to Second button, the onclick attribute does not execute because Firebug says proceedToSecond is not a function
button code:
<input type="button" id="proceed" name="proceedToSecond" onclick="proceedToSecond();" value="Proceed to second form">
I had the same problem, and it's because you have a form with the same name as your function. JavaScript doesn't seem to be able to distinguish between the two, so you get the "not a function" error.
Maybe there is an error in your Javascript before that snippet given by you. If so, the rest will not be parsed by Firefox and then your function will not be defined.
The problem was resolved by changing proceedToSecond() to doIt() in both the call and the function name. I have no idea why
Hmm... I always used javascript:function_name() instead of function_name() because a few times the javascript didn't run. The name tag for the html snippet might have to be changed to a slightly different name because javascript might be getting it mixed up. Can you show us the entire javascript file because there may be a mistake/syntax error somewhere at the bottom/top.
It works on my computer, Firefox 3.5.5, Firebug 1.4.3, when inserting your code into an empty html document (<html><head/><body> code </body></html>)
Maybe there is another bug somewhere in your DOM, or in some of your other functions?
Could you possibly paste the entire source here, or maybe on a pastebin site?