|
Good Day all
i am reluctantly maintaining a Classic Asp application that will be re-written in few months to come. i have an issue where i have a Code like this
if(document.frmEntry.optMethod != "undefined")
{
if (document.frmEntry.optMethod.selectedIndex == 0) {
strPrompt=strPrompt+'Please specify the Valuation Method\n';
if ( objFocus == null ) {
objFocus = document.frmEntry.optMethod;
}
}
}
my problem here is that even if document.frmEntry.optMethod is not equal to "undefined" the code still go into the condition as if it was true. i have attached a proof in my debuger.
http://www.vetauinvest.com/Example/IE_DEBUGGER.png[^]
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa[at]dotnetfunda.com
http://www.Dotnetfunda.com
modified 3-Aug-14 15:47pm.
|
|
|
|
|
Try using a Falsy check.
The following values are always falsy:
false
0 (zero)
"" (empty string)
null
undefined
NaN (a special Number value meaning Not-a-Number!)
Your code should look like as follows:
if(!document.frmEntry.optMethod)
{
if (document.frmEntry.optMethod.selectedIndex == 0) {
strPrompt=strPrompt+'Please specify the Valuation Method\n';
if ( objFocus == null ) {
objFocus = document.frmEntry.optMethod;
}
}
}
|
|
|
|
|
You are very true about 'false' check, but sometimes it is a good practice to write full code and explicitly state against what are you want to check. It's of course only a matter of maintainability/readability...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
That should be undefined and NOT "undefined" !!!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
The "undefined" shown in the debugger is not a string, so you can't compare it as one.
To really test if your value is undefined, you can use this:
if(typeof document.frmEntry.optMethod != 'undefined')
The typeof operator returns the type of the argument as a string.
|
|
|
|
|
I can't see why use undefined as string - with or without typeof!?
In JavaScript undefined is a value property of the global namespace and yous should use it according to it...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Thank you , this info is enough to solve the issue.
thanks again
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa[at]dotnetfunda.com
http://www.Dotnetfunda.com
|
|
|
|
|
The typeof for an undefined value is always "undefined". The value undefined being in the global namespace opens up some possible problems:
function madness() {
var a = 'fish', undefined = 'fish';
if(a === undefined) {
}
}
function mistake() {
var a = 'fish';
if(undefined = a) {
}
}
I know these are pretty unlikely scenarios, but better safe than sorry.
In earlier browsers "undefined" was not a testable value so expressions like (a == undefined) would produce the helpful message "undefined is undefined".
|
|
|
|
|
Graham Breach wrote: The typeof for an undefined value is always "undefined".
How that?
var undefined = 'fish';
alert(typeof undefined);
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Yes. If you define undefined as a string variable, then it is no longer undefined and things get confusing.
This is why I was testing the type of the value against the string "undefined" - the string is a constant.
|
|
|
|
|
You can try with remove ("") double quotes OR use ('') single quotes.
modified 9-Sep-14 7:56am.
|
|
|
|
|
I'm reading a tutorial about using selectors in jQuery to modify items on the page. I understand most of it, except I can't figure out why the first line of code below uses a comma to separate the selectors, and the second code line does not. Can anybody tell me when the comma is used and when not?
$('footer, header').slideUp('slow').slideDown('slow');
$('#Sidebar img').fadeTo(5000, 0.1);
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Thank you.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I'm working on a task where given the coordinates of a line from point A to point B, I need to create a polygonal geofence around(50meters) this line (road route) in google maps.
Can some one help with this?
|
|
|
|
|
|
|
Please, I am using two javascript files, which has its own assigned worked, on a php page, however the jquery script stops working while the JSON2 script works.
This is how I implement both on the php page
<script type="text/javascript" src="jquery.min.js" ></script>
<script type="text/javascript" src="JSON2.js" ></script>
The link to the jquery file http://code.jquery.com/jquery-1.11.1.min.js
The link to JSON2.js :
https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js
**Question**
Please, is it possible to use both script on the same page? if yes, please how to I go about it?
Thanks for helping.
|
|
|
|
|
I'm unaware of any issues using the 2 together. It would help if you could tell us what is happening.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
This is what i see in my web console log
SyntaxError: JSON.parse: unexpected character , this is found in th json.js
TypeError: Q[a].exec is not a function , this is also found in the jquery.js
|
|
|
|
|
Does your code have errors?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hi, i think i have solved it,I was previously using json and now i have to changed it to json2
|
|
|
|
|
I have this list of items in a div container, so each item has it's own container. It's a long list of previous orders, a ticket list on the left.
You can click on the container, and the background-color will change, and it will fire a function that accesses a web service, and create a ticket for the item on the right.
LEFT SIDE | RIGHT SIDE
ORDERS | ORDER TICKET PREVIEW
I want to disable the click on the left, the orders, while the ticket on the right is created, so dumb users don't click the thing to death.
I'm not sure how to go about this one, looking for ideas. I wrote it in Javascript, with a little jQuery mixed in.
I was looking for a neat clean way to do this, without globals and chopping it up. I can't see how I can recreate the complex onclick to enable it again, and don't understand what happens to the vars I pass.
Perhaps I can somehow disable the whole container from the click, preserving the underlying click.
So this runs in a for loop, and creates a container for each previous order, with order data inside it.
Hope I was able to convey my thoughts here clearly.
function build COH_List() {
var div_item_container = document.createElement('div');
div_item_container.id = m_ID;
div_item_container.className = 'div_item_container';
div_item_container.style.width = '100%';
div_item_container.style.height = '42px';
div_item_container.style.margin = '3px 0px';
div_item_container.style.borderBottom = "dotted 1px rgb(200,200,200)";
div_item_container.style.display = 'block';
div_item_container.style.cssFloat = 'clear';
div_item_container.onclick = (function (m_ID, m_orderID, m_orderNumber, m_orderDate) { return function () { select_order_click(m_ID, m_orderID, m_orderNumber, m_orderDate); }; })(m_ID, m_orderID, m_orderNumber, m_orderDate);
div_items_container.appendChild(div_item_container);
And then I have a function below that builds the order ticket.
function load_orderDetails() {
}
|
|
|
|
|
have you tried...
element.onclick = '';
maybe write your handler like so.
function load_orderDetails(ele) {
ele.onclick = '';
}
just make sure when you call it you pass it the element that you want disabled. just by chance are you using jQuery because there are message handlers that will do this for you??
|
|
|
|
|
I'll give that that a try later today. Good Idea!
Will let you know the outcome.
|
|
|
|