|
Thanks,
I was wondering it I had to initialize the object like a structure in c++
The 33 was a mistake, suppose to be != ""
Let me try it today
|
|
|
|
|
I am looking through JavaScript and searching the web to try to learn what it is doing. I see this as the first line of text. var RVIPath = RVIPath || {};
I know the || is a logical operator for OR. But the rest makes no sense to me.
|
|
|
|
|
I'm not sure what you're looking at. But what that does is assigns a new blank object ( {} ) to that variable if it didn't previously exist. (Actually, it also does it if that variable contains 0, false, an empty string, null or possibly an empty object or array, as well as undefined. But I'm sure its purpose is to ensure it is assigned to something before further processing.)
|
|
|
|
|
Thanks Bob.
But why the OR operand?
Here is the rest of the code:
// This function will open a new window with the URL of the Image requested.
OpenImageWindow = function (ImageViewer, RVIPath)
{
if (RVIPath != "XX") {
var hgt = screen.height - 20;
var wdt = screen.width * .5;
var lft = 1100;
var window_chrome = "toolbar=no,resizable=yes,height=" + hgt + ",width=" + wdt;
cas_window1 = window.open(RVIPath, "NewWindow", window_chrome);
cas_ window1.focus();
}
}
// This function will read thru a subfile and determine if the the Image field has a "Y" in it.
// If it does then it will set the field to " " and display the Scanner Images.
// If it does not then it sets the field to " " and leaves the URL blank.
DisplayScannerImage = function (elementsLength, imgCharField, imgImage, ScannerPath, startingID)
{
var startpoint = startingID;
var next = startpoint;
for (var i = 0; i < elementsLength; i++) {
var imgtext = document.getElementById(imgCharField + next);
var imgUrl = document.getElementById(imgImage + next);
if ($(imgtext).text() != 'Y') {
$(imgtext).text(' ');
$(imgUrl).hide();
}
if ($(imgtext).text() == 'Y') {
$(imgtext).text(' ');
$(imgUrl).attr('src', ScannerPath);
}
next = next + 1;
}
}
|
|
|
|
|
fellathedog wrote: But why the OR operand? It's a shorthand way of saying:
if (RVIPath != NULL)
RVIPath = RVIPath;
else
RVIPath = new object;
if (RVIPath == NULL)
RVIPath = new object;
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
We had a missionary from Japan Sunday at church that said "the Japaneese language was created by the devil", in reference to it being hard to learn. Coming from a very safe comfortable environment to the web sometimes makes me think the same about JavaScript. I will learn this and be looking back and laughing at this comment. Thanks.
|
|
|
|
|
fellathedog wrote: I will learn this and be looking back and laughing at this comment.
As we all do from time to time ...
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I don't know where the NULL comes from there. It is shorthand for
if(!RVIPath) RVIPath = {};
If RVIPath is assigned, but set to something which evaluates to false, it will be reassigned.
|
|
|
|
|
Which is shorthand for
if(RVIPath == NULL) RVIPath = {};
The expression !object means object equals NULL .
if(!RVIPath)
if(!(RVIPath == NULL))
if(RVIPath != NULL)
One of these days I'm going to think of a really clever signature.
modified 23-Jul-12 13:48pm.
|
|
|
|
|
Javascript is loosely typed. There's no guarantee that RVIPath was of type 'object' before arriving at this statement, and there are various other values it could have which would evaluate to 'false'.
|
|
|
|
|
I was merely trying to explain syntax to OP, and I think my answer did that, and still holds true whether RVIPath is an object, a number or anything else.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I've gotten in the habit of doing !object with javascript because it is the least like any other programming language. Getting into the details of == and === in javascript is just too much of a PITA.
|
|
|
|
|
I have been doing that for nearly 30 years since I first read Kernighan & Ritchie[^]. I don't find Javascript that different, syntactically, from C or Java.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Funny, it must be one of my handicaps from learning C++ before C. I think the vogue at the time was to avoid shortcuts like that and avoid shortcuts like if (!x) for pointers.
Richard MacCutchan wrote: I don't find Javascript that different, syntactically, from C or Java.
Once I got into the details of it, the common syntax made things more complicated for me than if it was more foreign. When I read javascript now every time I see x != null instead of !x or x !== null, I immediately leap to the conclusion that the author is still thinking that everything works like C# and there are probably subtle bugs lurking in the code. Using the full on javascript style is a message to my future self that the code was written when I better understood the way javascript works.
|
|
|
|
|
This relies on the truthyness/falseyness concept in javascript, and the fact that as part of a boolean operation, javascript will coerce things to truthyness or falseyness.
Falsey values in javascript are 0, null, undefined
So what this code says is "If RVIPath is truthy, assign its value to RVIPath. Otherwise assign an empty object to RVIPath"
It is a shorthand equivalent of
var RVIPath = null;
if(RVIPath)
RVIPath = RVIPath;
else
RVIPath = {};
|
|
|
|
|
Hi all;
I have an ActiveX control that use it's functionality in a html file, so that I call it's methods and properties
using a javascript function as below:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
fieldset {
border-color: #000;
border-width: 3px;
border-style: solid;
padding: 10px;
margin: 0;
min-width: 400px;
max-width: 800px;
width: 800px;
}
fieldset legend {
color: blue
font-size: 1.1em;
}
fieldset label:first-letter {
text-decoration: underline;
}
input, textarea, select {
width: auto;
margin: 5px 0 0 10px;
}
.style1
{
width: 25%;
}
.style2
{
color: #0000CC;
font-weight: 700;
}
.style3
{
width: 213px;
}
</style>
<script type="text/javascript">
function OnGenReq()
{
var ret = MyOCX.GenerateReq(Text1.value, Text2.value, Text3.value, length1.value, Text4.value);
document.getElementById("demo").innerHTML=ret;
myreq.value = MyOCX.ReqString;
}
</script>
</head>
<body>
<p id="demo"></p>
<object id="MyOCX" width="0" height="0" codebase="C:\Users\Administrator\Documents\Activex.cab"
classid="clsid:8F91127E-A84B-4FBD-AB43-AA63A63C0BE5">
<param name="_Version" value="65536">
<param name="_ExtentX" value="2646">
<param name="_ExtentY" value="1323">
<param name="_StockProps" value="0">
</object>
<p></p>
<fieldset>
<legend class="style2">Generate Request:</legend>
<label for="Text1">First string Arg:</label><input id="Text1" type="text"><br>
<label for="Text2">Second string Arg:</label><input id="Text2" type="text"><br>
<label for="Text3">Third string Arg:</label><input id="Text3" type="text"><br>
<label for="length1">Length value:</label>
<select id="length1">
<option selected="selected" value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
</select><br>
<label for="Text4">Forth string Arg:</label><input id="Text4" size="30" type="text"><br><br>
<label for="gen"></label><input id="gen" value="Generate Request" type="button" onclick="try{OnGenReq()}catch(e)
{alert(e)}"><br><br>
<center>
<label for="myreq">Req String</label><br><textarea id="myreq" rows="15" cols="66"></textarea><br><br>
</center>
</fieldset>
</body>
</html>
As you see in the html code, I have a tag with "myreq" id that want to display "ReqString" value (that
is a custom property of the activex) into textarea.
When I click "Generate Request" button, "MyOCX.GenerateReq" method runs to assign a string value to "ReqString"
property. But when I assign "MyOCX.ReqString" value to "myreq" to be displayed in the textarea using either:
myreq.value = MyOCX.ReqString;
OR
document.getElementById("myreq").value = MyOCX.ReqString;
I get the error "ReferenceError:'myreq' is undefined", while "myreq" is defined within the <fieldset> tag!
Could you tell me what's wrong with this code?
TIA.
|
|
|
|
|
creative26 wrote: I get the error "ReferenceError:'myreq' is undefined", while "myreq" is defined within the tag!
No it is not defined.
myreg is not the same as "myreg", for the latter is a array of chars, because it is enclosed in doublequote marks.
You may do the following, but no guarantee that it will work, because I have no idea what your trying to accomplish
var myreg = MyOCX.ReqString;
|
|
|
|
|
He, he, he, ha.
SA will smile when/if he reads this.
Have you tried looking at the code in a syntax hi-lighting editor? Have a very close look at the HTML for your button.
Last time I checked, ö nclick is not a function. Get rid of that accented charater and replace it with an 'o'
That's right - your code was never getting called. Using the javascript debugger in your browser may have told you sooner that the onclick event wasn't firing.
But I picked it up in Notepad++ since the word wasn't coloured red
önclick = "try{OnGenReq();}catch(e){alert(e);}"
onclick = "try{OnGenReq();}catch(e){alert(e);}"
|
|
|
|
|
I'm not so sure about that. I've seen other messages in CP forums where cut'n'paste seems to mutate lower case o into an accented one. I haven't seen enough occurrences to pick the pattern, but I'm sure there is one.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
I don't quite follow - "I'm not so sure about that" not sure about what?
I realize there's been quite a few of these onclick --> önclick occurances. SA made the first comment I saw about the trend, hence the reference to him.
I'm still waiting to see anything to suggest to me that it's not the source of the copying that's erroneous. It's not like every instance of o is replaced with ö.
There's also only 1400 results on code project for 'önclick=', dating back to 2009.
Whatever the source, I'm sure getting frequent laugher miles from them.
|
|
|
|
|
Not sure that the accented 'o' was actually in the source that OP pasted from.
As you noted, there are many occurrences, and I can't imagine all those members posting the same error. Hell, most of us couldn't even generate that character on our keyboards!
I remain to be convinced that it's not an artefact of the cut/paste process. Some weird interaction between clipboard and browser?
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Ah, now I understand.
Yeah, it was my initial thought - perhaps something in non-english character fonts being converted back and forth.
Though there's only 1 instance of önmouseup= in codeproject (google: 'site:codeproject.com önmouseup=')
Fun, fun. Alan Turing would be so bored....
_in_2780 - It's just occurred to me - don't s'pose you live in Katoomba?
|
|
|
|
|
enhzflep wrote: live in Katoomba?
Got it in one! Also, an obscure reference to the first bisync protocol I implemented in the dark ages of the 1970's.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Woo-hoo! I've looked at your username dozens of times and tried to work out what the number could have referred to. I kept coming back to the idea that it was a reference to a time ~ 800 years from now. Last night the penny dropped like a sledgehammer.
Guess what? I figured out where the ö character comes from. You were spot on - there's a pattern alright.... It's a deliberate feature of the board!
If you enter some javascript into the editor and it contains onXXXXXX functions in it, the first letter in the preview gets changed to an ö _unless_ it has been html encoded. Alan would still be bored though..
Example:
Good - pre-block + html encoded
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="this.disabled='disabled';">Disable Me</button>
</body>
</html>
Good - html encoded
<html>
<head>
</head>
<body>
<button onclick="this.disabled='disabled';">Disable Me</button>
</body>
</html>
Bad - in pre tags, not html encoded
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="this.disabled='disabled';">Disable Me</button>
</body>
</html>
Bad - neither contained in pre block nor html-encoded
Disable Me
|
|
|
|
|
Good one!
Your next assignment is to work out a script injection attack against which that character substitution is the defence.
OT: Where are you? If you're in a timezone near me, you keep pretty weird hours.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|