Logical Operator Not Working - How To Make It Work
Jul 14, 2010
What kind of logical error am I making? I want the alert(); to execute if both of the variables (cjob and czip) are blank, but the only way I can get it to work is if I replace && with ||.
anotherVar should be -1 if there are no matches, but it doesn't seem to work var string = "abadafa"; var matches = string.match(/a/gi); //doesn't work with /z/ for example
var anotherVar = matches.length || -1; The default operator should return the second value if the first is null or false, and according to try { alert(matches.length);
I have a webpage with addition questions for numeracy training. I am storing the sums in a table(id="sums"), with an empty textbox(id=ans1) for the user to type the answer. After the user types an answer and moves onto the next Q, I want to activate a popup dispaying if the answer is correct or not. I am tackling this with onmouseout. The script checks the answer, then displays a confirm message if correct or and alert message if wrong. The onmouseout is not working
I must have a syntax error, because this function crashes the entire script (even the other functions).
function newNote() { allNotes = document.getElementById('notes-stickies-app').innerHTML; secondadder = 1;
[code]...
EDIT: to get to the stickies part, click the apple menu, and click stickies. you'll see how the stickies wont drag because this script that adds new stickies has a problem.
This seems like a total beginner thing, but I don't know why it isn't working. I'm working from examples from a sitepoint pdf. Here's my html:
Code:
<body> <h1 id="stupid">sdfasd</h1> <p>sdjfa</p>
[code]....
When I run an if statement, I'll get an alert letting me know that the value of target is null, but why is it null? It should contain a reference to the h1 node.
I have a pretty simple function set up to pull XML data into my page, but there's a couple things wrong with it. I'm REALLY new to J Script and really trying my best to learn, but for some reason I'm not yet adept at googling the right results :rolleyes:At the very bottom you can see the data from the first XML entry, so it seems the function itself is working fine, but it's not looping coorectly to access all the data.Also, I want to pull it into the "shows" div of the page, but can't figure out how to put it there (seriously, I am very new with JS). The code below is not working, but the live site has it added to the body, which does show the one entry.Here's the XML function, the XML data and the HTML markup:
Shows function -
function loaddates() { var xmlData = document.getElementById("tourdates"); var newDates = xmlData.getElementsByTagName("dates");
Ok, this seems easy, but I am struggling. I have this...
$("a[href$='mp4']").click(function () { But I want it to work for mp4 or mov or more. Something like... $("a[href$='mp4'||href$='mov']").click(function () { <-- which doesn't work apparently
this will not work on change. also the innerhtml wont display. please help. here is the js:
function checkemail(){ if (document.suform.email.value && document.suform.emailcheck.value) { if (document.suform.email.value == document.suform.emailcheck.value)
I don't actually have a mac with which to test this, but I'm informed by a colleague that one of my scripts has failed in IE on the Mac; endless twiddling seems to point to the ternary operator as culprit.
I asked him to check that javascript:alert(true?"Yes":"No"); gave an alert when pasted into the address bar and he's reported that it does not. javascript:alert("someString"); works quite happily.
Can anyone confirm this bug or help narrow it to a single version? It seems a fairly large bug to have gone so under-reported, gooooogling for "mac ie ternary operator" doesn't return anything helpful.
Is there any way to call the new operator as a method (function)? The reason is that I've got IE as a COM object (Imagine I've brought up IE using VB) and it's easy to call every method of any DOM element (including window). But if I want to create a new object, then it's more complicated. Of course I could always execute js code (using window.execScript) which will create the object and save it as a variable on the window object and then pick it up from the COM creator, but really...
Consider the following page snippet which nicely adds an option to the empty select element. Of course, I could use the W3C createElement, addChild, muckWithDOM approach to avoid the execScript, but both of these are going to add huge amounts of time and substantial complexity to an otherwise one liner:
<form method=pos action=''> <select name=sel id=sel></select> <script type='text/javascript'> var sel=document.getElementById('sel'); sel.options[0] = new window.Option("foo", "bar"); </script> </form>
Can't I do something like window.Option.newInstance("foo", "bar") in place of the new window.Option("foo", "bar") ?
I have a for loop and would like to increment a variable for (let's say) 2 instead of one (++). How can I do that?
I have tried for instance x + 2 instead of x++ but when I try it in IE an error saying that a script is making IE to run slowly and then nothing happens. So how to do this?
<script language="JavaScript"> <!-- Begin var msg="I am flashing!"; var speed=300; var visible=0; function Flash() { if (visible = 0) { window.status=msg; visible=1; } else { window.status=" "; visible=0;:confused: } setTimeout('Flash()', speed); } // End --> </script>
We all know that feature detection technique works from very beggining of user-agents supporting JavaScript. We can alway check if eg. document has a write property or smth else:
if(document.write) { }
We could do that for all of objects, so i have been surprised when i found 'in' operator, which for above example would be used like this:
if("write" in document) { }
So i have questioned myself what for ? I can always do:
if(document["write"]) { }
or even var prop = [...]; if(document[prop]) { }
which is supported better then 'in' operator ('in' is supported since W. IE 5.5 and NN 6 - around 2000 year). I can only guess that 'in' was provided in W. IE 5.5 only for convenience... but that is my guess and someone more knowlegable could write here some more opinions on this operator...
How you might achieve the following without using eval()? I've come up a bit short: function addOrSubtract(operator) { var a = 10; var b = 5; var answer = eval(a + operator + b); alert(answer); } addOrSubtract('+') // alerts 15 addOrSubtract('-') // alerts 5
I cant get to know how can i make a dynamic box work with sql!i found this code online which takes in the values from database and puts it in combo box one,once a field in combo box one is selected the related field will be displayed in combo box two.its like country and state combo box but from sql database. it does not load from database the field for combo box one.