Which Operators Can Be Used With An IF Statement

May 3, 2010

a. only logical operators

b. only comparison operators

c. both logical and comparison

d. you cannot use operators with an if statement.

this is from my javascript book review for the chapter.

you can use both right? sounds silly i know but just want to make sure for my test.

View 4 Replies


ADVERTISEMENT

Why Bitwise Operators?

Jul 20, 2005

Why would one use bitwise operators? I can program in various languages in
some shape or form (C++, PHP, some scripting) and I've heard/seen bitwise
operators before, but never understood why anyone would use them - any real
world examples or ideas? Examples follow (that I am reading in my Core
JavaScript Guide 1.5).

15 & 9 yields 9 (1111 & 1001 = 1001)
15 | 9 yields 15 (1111 | 1001 = 1111)
15 ^ 9 yields 6 (1111 ^ 1001 = 0110)
in addition there are AND,OR,XOR,NOT and left and right shifts which would
only extend this post longer than nescessary...

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?

View 11 Replies View Related

Question About Operators

Apr 26, 2006

Searched W3Schools site for information on JavaScript operators.

It doesn't seems to be an all inclusive source.

It doesn't have ? or :

I did learn what ? means from a book... But what does : mean/do?

View 5 Replies View Related

JQuery :: Logical Operators In Selectors?

Jul 1, 2010

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

View 2 Replies View Related

Creating Calculator - How To Execute Operators

Jul 18, 2010

We are required to create a javascript calculator. The page should has 3 text box, first and second text box would allow the user to input numbers, the third textbox will show the answer. the arithmetic operations should be in radio button, drop-down list and the select option. I'm still working on the radio button and i don't how to execute the operators. How to grab the inputted number from the textbox and how to execute the operators.

View 1 Replies View Related

Conditional Operators Versus If Else Statements

Apr 28, 2011

I'd like to ask if it is possible to use conditional operators
var = condition ? var1 : var 2
To do the same job as the if-else statements I wrote in red below:
<p id="text">change text colour</p>
<br />
<a onclick="allsorting();">sort in both ascending & descending orders</a>
<div></div>
<script>
/* if & else */
function changetext(){
document.getElementById('text').onclick = function (){
swapcolour(this);
}}
function swapcolour(text){
if(text.style.color == 'black'){
text.style.color = 'red';
} else {text.style.color = 'black'}
} window.onload = changetext;
</script>

View 25 Replies View Related

Creating URLs From Function Call Operators

Jul 20, 2005

Is it possible to create URLs from function call operators?

For example, I'm trying to program an onClick function which will load a
webpage in one frame and an image in another, based on the name of the
button which is being clicked. So clicking the button with name="help" will
open "webpages/help_page1.html" in one frame, and "images/help.jpg" in
another.

To do this I was hoping that the following would work, where the function
had been called by

function activate(buttonName) {
webpageURL="webpages/"+buttonName+"_page1.html"
imageURL="images/"+buttonName+".jpg"
parent.frame1.location.href=webpageURL
parent.frame2.picture.src=imageURL
}

But this doesn't work, because the browser (IE6) looks for
"webpages[object]_page1.html" and "images[object].jpg".

View 2 Replies View Related

Slide Toggle Script And Conditional Operators

Aug 20, 2011

I've got a slide toggle script online and have got just one bit that I cannot figure out why. What is (toggled = !toggled)? What does it mean? Does that mean toggled = false? But I tested it, it seems not like that. And once the slide is toggled, it should use the minheight. Then the condition for var Height must be the opposite of (toggled = !toggled). Then what is (toggled = !toggled) like? Is that like (toggled != !toggled)?

<!DOCTYPE html>
<html>
<head>
<title>Avinash</title>

<style>
#slider {
margin:0px auto;
padding:0px;
width:400px;
border:1px solid #000;
background:#0f0;
height:0px;
overflow:hidden;
} .....

View 5 Replies View Related

Using Bitwise Operators To Post Different Alert Messages

Aug 25, 2004

I have been looking for a way to give something back to this forum as it has helped me greatly, and I am hoping that this might be of value to someone.

Basically I was just tired of consistantly commenting and uncommenting out alerts in my code so I wrote some code that would allow me to keep my alerts and only show them when I wanted to, and only the types of alerts I wanted to show.

I thought that using bitwise operators would give me the flexibility to specify different options and a quick way of finding out what options were wanted. There are other ways of doing this of course, and this is one approach.

The bitwise OR operator "|" says if one of the two vars has the bit set, then set the bit.
the bitwise AND operator "&" says if both of the two vars has the bit set, then set the bit.

It starts with my bitwise values:

var NONE = new Number(0);// 00000000
var ALL = new Number(1);// 00000001
var INFO = new Number(2);// 00000010
var LOCAL = new Number(4);// 00000100
var PARAM = new Number(8);// 00001000
var COUNT = new Number(16);// 00010000

These values are really important. Earlier I used 0 through 5 and because of the way bitwise operations work, COUNT was equivelant to ALL and PARAM. what you are doing is blending bits and then getting a value. So, in the 0 through 5 approach, COUNT was 00000101 (5). When I OR'd ALL with PARAM I got 00000101 which was a result of 00000001 with 00000100 (4)! So be really careful if you go this route to double check that no combination of vars will equal other vars.

In our constructor we get the value thus:

function FormCheckBase( objForm, blnStateIsDebug, sCulture )
{
this.Form= eval('document.' + objForm);
this.Debug= new Number( blnStateIsDebug );
this.Culture= new String( sCulture );
}

with this call:

objFrm = new FormCheck( 'FormName', INFO | LOCAL | PARAM, sCulture );

Then in the instance methods of the FormCheck class, I wrap my alert boxes.

if ( this.ShowErrorAlert( this.PARAM ) ) // or whatever other value you want.
{
alert( sWhoAmI + "iArrayLength: " + iArrayLength );
alert( sWhoAmI + "blnBlank: " + blnBlank );
}


ShowErrorAlert does a bitwise "AND" to see if we have a match. We are also testing for ALL, and if that is passed originally, we are returning a true to show the alert.

FormCheckBase.prototype.ShowErrorAlert = function( iAlertBit )
{
var bitCompareResult = new Number(0);
var showMe = new Boolean(false);

bitCompareResult = (this.Debug & this.ALL);
showMe = ((bitCompareResult == this.ALL) ? true : false );
alert( showMe );
if ( showMe == true )
return showMe;

bitCompareResult = (this.Debug & iAlertBit);
showMe = ((bitCompareResult == iAlertBit) ? true : false );

return showMe;
};

I also did a couple of helper functions that would change the Debug var before I went into a method and reset it after I was done. Sometimes you might not want every single method to start showing alert boxes. So I did a SetDebugBits that sets the value of Debug and GetDebugBits that gets the current value of Debug. Call GetDebugBits first to store the current value, then call SetDebugBits to set it to whatever you want to use, and then make another call to SetDebugBits with the original value to set it back.

We mostly call our FormCheck constructor with the value of NONE, and then work on a method by method basis as we have lots of methods in the class.

View 7 Replies View Related

If Statement Returning False On A True Statement?

Apr 4, 2011

my webstie allows users to change the color of the background, so to keep the text readable I have it changing as well.the color picker I am using has text boxes with rgb values 0-255 for each.I am trying to get one bit of text to alternate between red and blue with the conditions

Code:
if(blue>green && blue>red)
{

[code]....

View 2 Replies View Related

New Foo(); As A Statement?

May 12, 2007

I am reading the ECMAScript specs trying to figure out if the next
line is a legal statement or not new Foo();

I think the above code may only be legal as an expression and not as a
stand alone statement. Would this make the above a bug?

Douglas Crockford's JSLint will choke on the above line of code and
stop parsing. All the browsers seem to accept it as ok and work as I
expect: the returned object just doesn't get assigned to anything.

The time I have used a line like the above is when the constructor has
side effects and the "class" keeps track of all its instances.

Any ideas what is right or wrong in this case?

View 2 Replies View Related

IF Statement?

Jul 23, 2007

I have several text fields on page that I would like to make calculations based on if there is a number input in one of the fields.
So, if the price field is populated, the sale price field would populate using a function to do the calculation.


Now, how do I write the code for this to occur? I know how to get the function to fire based on clicking a submit button, but not sure how to do it simply based on a number keyed into the one field. Is this possible and if so, how?

View 4 Replies View Related

Is This Statement Correct?

Jul 23, 2005

What is the correct construct for accessing "pageYOffset" in another window?

I've tried this, but it doesn't work:

var mainPageYOffset;
//
mainPageYOffset = parent.main.window.pageYOffset;

View 2 Replies View Related

Time In If/then Statement

Aug 3, 2007

It's been a while since I've worked with javascript time comparison,
and I was wondering how I can say "if time < 15:30"?

The semicolon looks out of place to me, and indeed it has caused an
error.

View 7 Replies View Related

Using Null In If Statement

Jul 20, 2005

I remember using if statements with null in it. For example, at one
point I used this:

if (value == null) {
value = "something";
}

document.write(value)

However, this script causes an error in any browser. Why can't it
correct the value like it should?

View 1 Replies View Related

JQuery :: Use To Indicate The End Of The JS Statement?

Jul 13, 2010

For the following two snippets, they can all pass Firefox.However, I would like to know the rule of thumb when I have to use ; to indicate the end of

[Code]...

View 1 Replies View Related

While Statement Not Using My Vars?

Nov 14, 2011

I have a two fold question:1) Why would my while statement not be workingI have cleaned up my code a little (although not perfect) but my while statement is not behaving, it does not output any numbers on a console.debug (using google chrome, or any other browser for that matter) which from my understanding it should?and 2) Slightly out of the remit of this forum I suppose, but this code is quite lengthy and I know there are ways to make this more efficient I just dont know what they are?

function generatePurchaseFields(dom) {
new Ajax.Request('/control/?page=tldmaxyears&domain=' + dom, {
method: 'get',

[code]....

View 1 Replies View Related

Switch Statement

Nov 1, 2005

This is my first time using the switch statement. I would appreciate your suggestion on how to do this properly. I am trying to get customer age which is (age) and compare it with the monthly rate then the text msg will display in the textarea. Also, I am having trouble figuring out how I can defined my monthlyRate in the switch or do I need to this outside of the switch? Code:
}

View 10 Replies View Related

String In An If Statement

Apr 27, 2006

i have the following:

a1="asdf"

how can i check in an if statement whether contains a numeric only value and if not then alert.

View 6 Replies View Related

Purpose Of With Statement In JS?

May 16, 2009

What is the purpose of with statement in JS?

View 3 Replies View Related

Using || (or) In An If Statement Correctly

Dec 8, 2011

I am trying to test the id of three input boxes so that I can capitalize the first letter.

The fname and lname work fine but mi does nothing and I get no error is this because of the if statement or the fact that the mi only has one character?

View 1 Replies View Related

Using If Else Statement With Confirm Box

Apr 14, 2009

I need to give two separate alerts depending on what the user clicks when they click the "Submit" button. I am using a confirm box. If they click "OK" it thanks them for their order. If they click "Cancel" it should go back to the form. I have written the code that I thought would work but it will not.

function confMsg(){
var s
s = confirm("Click OK to Submit Order. Click Cancel to Cancel")
if (s=="true"){
alert("Thank You for Your Order!")
else
return;
}}

View 2 Replies View Related

Calculator With If/then Statement?

May 26, 2010

I am working on a script that calculates the rental rate for a property. I currently have this code and form, which works as I wish it to.

Code:
<script type="text/javascript">
function roundCents(amount) {

[code]....

View 3 Replies View Related

Optimize An IF Statement?

Aug 26, 2010

I would like to make the following statement clearner. I'm thinking something like the SQL "variable IN (value1, value2, value2, etc.)" operator.

Code JavaScript:
if((e.which > 47 && e.which < 58) || (e.which > 95 && e.which < 106) || e.which==8 || e.which == 46 || e.which == 37 || e.which == 39 || e.which == 13) return e.which;

View 4 Replies View Related

Get The Result For The Following SQL Statement?

Sep 7, 2010

How can I get the result for the following SQL statement using JavaScript?

SELECT branch, region, referral, COUNT(DISTINCT LPS) FROM table GROUP BY branch, region, referral

Data:

BranchClientReferral TypeLPS #
402036402430Psychological File Review30
402036402430Psychological File Review50

[code]...

View 4 Replies View Related

Use The Quotes In This Statement?

Mar 3, 2010

document.write("<img src=' "+r_image[rand_int]+" '>");

could it not be just written like this:

document.write("<img src='r_image[rand_int]' />");

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved