How To Increment Without A ++ Operator?

Jul 30, 2002

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?

View 19 Replies


ADVERTISEMENT

NOT IN / IN Operator

Aug 6, 2007

Just wonder whether jaavscript can perform the NOT IN / IN as below:

if form.mytext.value NOT IN ("MYTEXT") {
alert("Mytext");
}

I did try, but not alert is displayed ad not error shown as well.

View 5 Replies View Related

Mac IE Ternary Operator?

Jul 23, 2005

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.

View 4 Replies View Related

New Operator As A Method

Aug 13, 2005

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") ?

View 5 Replies View Related

Special Operator About Function

Dec 14, 2006

<script>
var sd=function(){
return{
f1:function(){
alert('f1');
},
f2:function(){
alert('f2');
}
}
}();
sd.f2();
</script>

when execute sd.f2();it will alert f1,who can tell me why?

View 5 Replies View Related

'in' Operator And Feature Detection Technique...

Feb 9, 2006

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...

View 22 Replies View Related

Pass Operator As Variable Without Eval?

Mar 10, 2010

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

View 3 Replies View Related

Statement Faster Than The Ternary Operator?

May 20, 2009

I'd like to know which is faster or have a better performance between :

Code JavaScript:
if (flag) {
var v = "something";
} else {
var v = "else";

[Code]...

View 8 Replies View Related

Missing Name After Operator Delete Keyword

Nov 13, 2010

this.delete = function(obj){
..
Is that it ? I can't have delete ? Or can this be written in some other way, including delete ?

View 4 Replies View Related

Increment A Value Each Day By One?

Jan 29, 2010

For a real estate website, I want to create a script which will tell visitors how many days a property has been on the market. For example say the property was posted on the site on 1/1/2009. I want the site to say "This property has been on the market for 394 days." .

View 3 Replies View Related

JQuery :: Combine 2 Click Events With Operator ||?

Sep 23, 2011

I want to combine two click events to one function.Is there a syntax way like when you click this or you click that do something [code]

View 1 Replies View Related

AND Operator - Alert Not Shown When Values Selected

Feb 25, 2009

I am trying to run some code that will check if the user enters two values from 'depart' and 'arrival' select lists that would make up an invalid journey:
var cdate, ctime, cdepart, carrive, cname;
with(window.document.example) {

cdate = date;
ctime = time;
cdepart = depart;
carrive = arrive;
cname = name;
}

if(trim(cdepart.value) == 'Uptown' && trim(carrive.value) == 'Downtown'){
alert('invalid journey');
cdepart.focus();
return false;
}function trim(str){
return str.replace(/^s+|s+$/g,'');
}

However when I select the values the alert is not shown? I think My syntax is okay, maybe not?

View 5 Replies View Related

Ternary Operator Syntax And Case Condition

Aug 22, 2010

It's well know that the ternary operator syntax is something like so:
Code:
(test) ? true doThis : false doThat
Suppose that in case condition is false we want do nothing. How to code "do nothing"? May I let it blank or there are an appropriate syntax?

View 10 Replies View Related

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 ||.

if(trim(cjob.value) && trim(czip.value) == '')
{
alert('Hello');
}

View 2 Replies View Related

Increment Var By 1 In Loop?

Apr 6, 2009

I have a loop that is running and I am trying to increment a number by one each time. Here is what I am doing, but each time it just writes out 1 for the value.

var i=1;
Start of Loop
document.write(i);
var i=i++;
End of loop

It just writes out 1 each time though.

View 4 Replies View Related

Increment By 1 Every 15 Seconds?

Sep 11, 2010

I need to develop this feature for a charity site displays a number that counts up 1 every 15 seconds. This is to show how many times a kid is abused in this country.

I figured this piece of code was a good start:

function doSomething() {
setTimeout('doSomething()',15000);
}

View 2 Replies View Related

Increment Fields

Nov 29, 2005

What I need is 2 form fields, an up link, and a down link. I want the user to be able to select one of the form fields, then increment, or decrease the number in the field that has been selected by clicking one of the links. How might I do this?

View 12 Replies View Related

How Increment The Value On Each Click ??

Apr 17, 2007

How to increment the value on each function call ? Suppose i had a function called addRow()

//js code
addRow(row)
{
var i = 0;
alert(i);
}

suppose this function is called with onclick event of button. when clicked first time it should alert 0, 2nd time => 2 3rd time => 3..

View 2 Replies View Related

Modulus Operator Is Not Working If Give Number More Than 24 Digits

Dec 7, 2009

If number is more than 24 digits, modulus operator is not giving correct output [code]...

View 4 Replies View Related

Default Operator ( || ) Doesn't Work With Empty Array?

Aug 13, 2010

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);

}
catch (e){
alert(e); //alerts null
} it's null.

fyi: http://helephant.com/2008/12/javascript-null-or-default-operator/

View 22 Replies View Related

Can I Increment Elements Each Loop?

Apr 15, 2011

I have written the follow code. It is meant to (when finished) output a table showing each member of the array PEOPLE. There Income ,there Tax bracket and there finally there total tax paid.The calulations in the if-else statements are correct.I have to create a loop that will go through the if else statements equal to the amount of the people in the array (This is no problem I have done this earlier)

My problem is when I try to add each element (PEOPLE) to the table or there indivual tax outcomes.Can I create a loop and increment in the elements each iteration to put on the table?(for there names) As I am not meant to store each iteration,it is to write to the table each time.This is the code I'm working on with out the loop.

<html>
<head>
<script>[code]......

View 17 Replies View Related

Increment Width Of Div OnClick?

Jul 15, 2011

I've got a div whose width I'm trying to modify when you click either the plus or minus button (incremental percentage-based).

The following is what I've written in an effort to accomplish this:

<script type="text/javascript">
function modify_jump(way) {
//check if we should increment or decrement

[code].....

View 1 Replies View Related

Increment Number In String?

Jun 27, 2011

I have a string "Slide1.jpg"

I need to increment it by 1 to say "Slide2.jpg"

I have split and sliced but I keep getting SlideNaN.jpg

Rather then fix my mess of code... There has to be a simple way of doing this..

View 5 Replies View Related

Increment Php Array Variable?

Jun 16, 2010

$i=0;
echo '<script language="javascript">
var dA = new Array();[code]...

here i want to increment $i above code is not working,

View 1 Replies View Related

JQuery :: Function To Auto-increment Certain Value

May 21, 2011

I'm trying to write some jquery that when a link is clicked it adds a number into a div. Every time the link is clicked it adds another number(previous number + 1). i have this but it definitely doesn't work function addnumber(X)[code]As it is now, the first click does nothing. The second click spits out "2<br>2<br>". The third click spits out "2<br>2<br>2<br>". The fourth "2<br>2<br>2<br>2<br>" and so on.

View 3 Replies View Related

HTML Tags Break - Won't Increment The Name?

Feb 5, 2010

The following is my javascript code to extend a form:

[Code]...

Everything works fine except for the counter/adding on to theName ( newField[i].name = theName + counter). I know exactly what the problem is... I just don't know how to fix it. If I remove the li tags, the counter will work fine and increment each "name". As soon as I put the li (see code above) tags back (or any html tag - I have tested others as well) - it breaks again and won't increment the name - it just submits the names without numbers and alas I have no usable post data. how to keep the html formatting there and still get the counter to increment the name?

View 4 Replies View Related







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