Function Definition Inside 'if' Statement

Oct 19, 2005

I debugged some html file and found this:

------------------------------------------------------------
<script language="JavaScript">

if ( some_statement ) {

function MyFunction ( some_argument ) {

some_function_statements;

}

}

</script>
------------------------------------------------------------

Is it allowed to define a function INSIDE some 'if' statement?

View 8 Replies


ADVERTISEMENT

Change Background Image With If Statement Or Call Function Inside Of If?

Jan 17, 2010

Basically I want to have a different background image for every time of the day. The function by itself works okay with onclick or onload placed in body.

function changesky()
{
document.getElementById("sky").style.background="url(back_morning.jpg) repeat-x";

[code]....

View 5 Replies View Related

Use Prototype Or Closures Inside Functinon Definition?

Aug 7, 2009

Is it better to use prototype when declaring classes or is it better to use closures inside the definition, e.g.:

Code:

Code:

What are the main differences, and is one method preferred to the other?

As use of the class is the same, I can't really decide which to use.

View 2 Replies View Related

Using Eval() For Function Definition

Feb 19, 2007

I have this particular problem with eval() when using Microsoft
Internet Explorer, when trying to define an event handler. This is the
code:

function BigObject()
{
this.items = new Array();
this.values = new Array();
this.addItem = function( item )
{
this.items[this.items.length] = item;
}
this.makeHandlers()
{
var i, length = this.items.length;
for ( i = 0; i < length; i++ )
this.items[i].onclick = function()
{ alert( this.values[i] ); };
}}

However, this last code (makeHandlers() method) doesn't work since the
expression "this.values[i]" automatically belongs to this new
anonymous function, and therefore isn't valid (since the new anonymous
function(s) don't have the "values" attribute. So I tried the
following:

this.items[i].onclick = eval( "function() { alert( " +
this.values[i] + "); }" );

and it worked! ... in Firefox only :( Internet explorer returns
"undefined" for eval( "function() { /* whatever */ ); } " ), for the
same things Firefox perfectly understands, and if I try to make it a
handler, an exception is fired in IE. What do I do? Did I come to the
right conclusion with IE or am I making a banal mistake? Do I need to
find another way of solving this or is there a fix to this solution?

View 7 Replies View Related

Q About Function Definition Syntax

Aug 23, 2007

I had a look at sIFR.js code after parsing it and I have a question
about function syntax. For example

var f=function(){
// statements here
}();


What is the purpose if the second set of parentheses following the
closing brace? Is the intention to execute the function immediately
after it has been defined?

Most functions in sIFR.js do not have this syntax, but a few do.

View 1 Replies View Related

Recursively Calling A Function Within A Class Definition

Aug 13, 2007

i've got an object and i'd like to recursively call a function
within the class definition.

(i've simplified the code )

function myclass()
{
this.loop = function(index)
{
// ..work

setTimeout( "loop(" + (index+1) + ")", 100 );
}
}

does not work.

i've also tried

setTimeout( function() { loop(index+1) }, 100 );

i've also prefixed this. to loop in both cases - and no workee.

i think it's some sort of scope problem.

View 1 Replies View Related

Returning Reference To Function Definition When Using Self-Invocation?

Mar 26, 2011

I have this code:

HTML Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>

[code]....

The practical scenario is I have several functions attached to the jQuery ajaxSucess event. Each function needs to execute once during initial load and after when the JQuery ajaxSuccess event is fired. So I am just looking to see if I can eliminate a a few lines of code and learn something new in the process, that is really all.

View 7 Replies View Related

JQuery :: If Else Statement Inside Each Loop

Aug 3, 2010

I'm currently trying to produce an HTML table from an XML feed, using jQuery. And this works great! With an "each" loop, there now is a nice table on my screen, displaying the right information from the feed.

I would like for each new row of this table to have a separate color. For example:
row 1 - blue
row 2 - green
row 3 - blue again
row 4 - green again
...
and so on...

What I've tried, is putting something like this inside the loop:
var
x=0
(this line should probably be outside of the loop, but that doesn't seem to work)
if
(x=0)
code 1...
x=x+1
else
code 2...
x=x-1
But this doesn't work.

View 2 Replies View Related

Sending $_posts Inside Javascript If Statement

Mar 25, 2006

I have interrupted a login process (going to another interim page) to access the database and retrieve the zip code of the customer (don't ask :-). so they can agree or disagree (disagree is a javascript:back)

there are 3 $_post variables which i need to send on from within a confirm() to the login script.

Can this be done? They have to be $_post, rather than $_get

Is there a php alternative to the confirm? ( if so, i'm in the wrong place!!)

View 7 Replies View Related

More Than One Return Statement In Function?

Jun 29, 2011

I have a desire to include more than one return statement in a function I have written so that when it has found the solution to a hit-testing series of conditionals, it returns the solution. The desire is to avoid further hit-tests when solution has been found. I've always felt that more than one return statement in a function is poor style, since it may lead to false execution of a function - by way of a later code edits - making a mistake by forgetting the multiple returns. My function is short and maybe the optimisation exists only in my head but are there serious reasons why one should not have more than return statement? This JS code executes in the Quartz Composer framework and has nothing to do with we programming (context (-:)

Here it is with three returns, it 'works' and I could replace all the break statements with return statements to finish optimizing:
//Test for y inside range for all quads ( Quad is defined by 4 points in a row in the list is a quad ie. list[0-3], list[4-8],
//Test along the unit numerals (_N) and also the 'Revert Patch' button
if (y >a[0]["Y"] && y <a[2]["Y"]) {
for (i=0; i <37; i+=4) {
//Log("DDDDDDD "+i+" X:"+x+" Y:"+y); .....

View 3 Replies View Related

Returned Statement Outside Of Function?

Oct 5, 2011

we are using Map guide for viewing maps and printing.

while printing a map the above mentioned error (Returned statement outside of function) is coming

View 1 Replies View Related

JQuery :: Can The Click() Function Be Used In An If Statement

May 25, 2009

I would like to know whether a jquery click function can be used in an"if" statement.The reason why I am asking, is because I haven't seenany examples of this being done on the web. I want to use thisapproach because currently Jquery keeps initiating two events from onemouse click, eventhough the css for each element is different.Ithink the best way to avoid this problem is to use flow control toexclude the other mouse click event. If element A is clicked then

View 3 Replies View Related

Pass A False Statement Out From A Function

Aug 9, 2010

if i group some javascript into a function that returns false; how could i carry that 'false' out of the function so it can be used outside the function.the example below shows the validate function checks for a condition then returns false if it is met. i want this false to then be passed out of the function to then throw an error in its containing function. (goal to prevent the submitting of a form)i dont want the proceed function to be called, so how can the other function prevent this.Now i realise that the validate function could be incorporated into the top level function but, my form will eventually be quite large with a multiplitude of fields so i need to know how i can call back to functions and use them as objects insteasd of repeating lots of code.

View 7 Replies View Related

JQuery :: FAQ Show / Hide Function - If Statement

Jun 24, 2010

I have a simple FAQ show/hide function set up however I am having trouble setting up an if clause. My code is:
$(document).ready(function(){
$("dd").hide();
$("dt").click(function(){
$("dd").hide('slow');
$(this).next().slideToggle();
});
});

However, when you click on the same item twice it firstly hides and then reshows it, I need an if statement that basically states;
if "this?!" is visible/shown
Then do nothing
else
$("dd").hide('slow');
$(this).next().slideToggle();
I am unsure of the syntax and can't figure out what property I can trace out to see if the item is being shown or not.

View 4 Replies View Related

JQuery :: If Then Statement Not Working Within A Success Function

Apr 29, 2010

Why my page is not redirecting within the if then statement.

Here is the code:

I have tried this without the if then statement and it works fine. I am not sure why my if then statement will not work within success function, am I doing something wrong?

View 10 Replies View Related

Call A Function In A Meta Refresh Statement?

Jan 18, 2010

Is there a way to call a javascript function in a meta refresh statement? I'm refreshing my page but if I have data in my fields I don't want to loose them. If I can call using a JS function then in that function I can call the Submit function and save my data in the called script.

My syntax below doesn't fire the JS function:

<meta http-equiv="refresh" content="30;url=javascript:auto_refresh();">

View 1 Replies View Related

JQuery :: Using Click Function How To Add Or Statement Syntax?

Dec 4, 2009

I have an ID like this: $('#id').click(function(event){Do stuff after click

}); Can I have it also have a conditional or statement

$('#id').click || $variabe=='something' (function(event){
});

What is the proper syntax for something like that?

View 5 Replies View Related

How Can I Embed JavaScript Function Calls In A Document.write Statement?

Jul 23, 2005

I am getting syntax errors in my JavaScript code, code snippet as follows
(between my <script></script> tags:

View 2 Replies View Related

Function Method - Write Frist Program Through Return Statement ?

Nov 7, 2009

What is return statemen? what is functionn statement ? how can i write my frist program through return statement?

View 1 Replies View Related

JQuery :: Function Returns The Code Inside The Function?

Aug 29, 2011

I am having a strange problem with a javascript function that does not return the value but returns the code inside the function. My best guess is that I am incorrectly calling the function hasLandedOn()and jquery is interpeting it. Why is this happening? I highlighted the parts in red.-Tom ReeseThe following is returned NOT the variable imageName.

function hasLandedOn(){
var selectorLoc = $("#selector").offset();
var imageName = "";

[code]....

View 2 Replies View Related

My Function Works Only If Alert Function Exists Inside It?

Jan 17, 2011

I have what I think is a strange issue but others may see something I am missing.I am using AJAX functionality to process a php script on a server and then place the output of the script into a div element.Here is the code snippet

Code:
function doWork13(typeCode,colorBlockName,objectCategory,imgID){
httpObject = getHTTPObject();
if (httpObject != null) {[code]....

This code shown here works perfectly BUT....I do not want the alert message to be there. When I remove that line of code the script fails to function. There is no error just nothing happens.The function is to replace one image with another and the variable in question is simply the ID tag of the particular image being modified.As I said it works with the alert but does not with out, could it be a timing issue in that the alert gives enough time for the if statement in the setOutput13 function become TRUE

View 6 Replies View Related

Passing Data To Another Function Inside A Function

Feb 3, 2010

In one variable i have some data ex: var data = document.getElementById("imageId").value; I want to pass this data to another function inside another function ex: var button1 = '<img src="images/Remove-button.gif" width="70" height="15" onclick="removeVerifyImageRow(this),saveLibData('+data+')"/>';

while running the application i am getting an error incase if the data is string ex:if data is 'image1' i am getting an error, but with number there is no problem ex: if data is '1122'.

View 7 Replies View Related

Passing Variable To A Function Inside A Function?

Feb 10, 2010

Here is the code:

for (var i = 0; i < BS_crm['activityTypes'].length; i++) {
var clickFunc = function(){ activityList.showForm( -1, {blockType:[""+BS_crm['activityTypes'][i]['id'], "0"]} ); };
var type = {

[Code]....

Now, basically what I am doing here is running through one array to create an array of objects, that will be used to create links that will use whatever onClick function I pass it. The problem is that on the second line I need the BS_crm['activityTypes'][i]['id'] to be a value, not a reference. If that line was simply changed to:

var clickFunc = function(){ activityList.showForm( -1, {blockType:["3", "0"]} ); };

View 4 Replies View Related

Passing Data To Another Function Inside A Function?

Feb 3, 2010

In one variable i have some data ex: var data = document.getElementById("imageId").value; I want to pass this data to another function inside another function ex:

var button1 = '<img src="images/Remove-button.gif" width="70" height="15" onclick="removeVerifyImageRow(this),saveLibData('+data+')"/>';

while running the application i am getting an error incase if the data is string ex:if data is 'image1' i am getting an error, but with number there is no problem ex: if data is '1122'.

View 5 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

Definition<b>s</b> Of Week Number?

Jul 23, 2005

Throughout the world in general, ISO 8601 Week Numbers are used, in
which weeks are numbered 01 upwards and Week 01 contains the first
Thursday of the Gregorian Calendar Year.

There are, however, odd parts of the world where that standard is not
followed.

Ignoring for the moment cases in which week 1 is not more-or-less at the
beginning of the calendar year, what other definitions, stated exactly,
are used?

View 4 Replies View Related







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