How To Set Default Value For Function Parameter?

Apr 21, 2007

I've been searching now for quite a while trying to look for a way to give the default value to a function argument if it's not given. For example, in php one would do the follow:

function func_name(foo = 'default') {
...
}

In the above case, if foo isn't supplied while calling for the function, then foo would default to 'default'. I have tried that in javascript, but it doesn't appear to be working, so I am wondering how should I do this in javascript?

View 17 Replies


ADVERTISEMENT

JQuery :: Call Back Function - Should The 1st Parameter Of The Get Function Be A HTML File

Jun 23, 2010

I have just started learning JQuery and have a doubt in the below code. $.get('myhtmlpage.html', myCallBack);The doubt is should the 1st parameter of the get function be a HTML file or can it be a unction name?

View 1 Replies View Related

Call Function In Script And Pass One Parameter To Function And Its Returns String Value?

Feb 15, 2012

I want to call java function in javascript.In which we pass one parameter to function and its returns String value which I want to display in alert message.

View 2 Replies View Related

Calling A Function From A Parameter Of Another Function?

Jun 29, 2009

Captions for the images are called from the parameters of the main function and delivered into a span or div tag with the appropriate id. A very important part of what needs to be in the captions is text compiled by a separate function, in the project library.I've tried this with and without curly, square and round brackets, with and without semicolons and quotes- all with varying results. Sometimes the function is called, but it appears at the very top of the page and nowhere near the proper <span> tag.

addImage(a,b,c,d);
// filename, image name and caption are in a, b and c.
// d is the variable where I need to write my other function...
addRef(t,s);
// I need to put addRef in the d parameter of addImage.

View 6 Replies View Related

Pass Function With Parameter To Another Function?

Apr 18, 2010

Is there any way to pass a function(with its parameters) to another function using a parameter?

Examples:Here is how I do it now:

function output(text){
alert(text);
}
function bla(text, func){

[code]....

View 4 Replies View Related

Function As A Function's Parameter Like SetTimeout()?

Mar 7, 2011

How can I have a function parameter in a function?

Something lke setTimeout();
setTimeout(function() {
how can I do it like this?

[code]....

View 4 Replies View Related

Boolean Function Parameter

Jul 23, 2005

I have a simple JS function that I want to return a true or false value
based on the parameter passed in. At this point of time I receive the
error "'True' is undefined". Here is my code below.

JS Function -

function ShowSpecifiedPeriod(pShowPeriod){
document.mfperformance.ShowPeriod.value = pShowPeriod
document.mfperformance.method = 'get'
document.mfperformance.action = 'composite_requestdata.asp'
document.mfperformance.submit();
}

ASP Event Handler -

onclick="ShowSpecifiedPeriod(<%If bShowPeriod = false then
Response.Write true else Response.Write false%>)"

The ASP variable bShowPeriod is set based on the hidden form field
"ShowPeriod" and the initial value is set to false.

More than likely this has to do with the boolean Parameter but I am not
sure how to handle this in JS. I have tried the following but receive
the same results.

function ShowSpecifiedPeriod(boolean pShowPeriod) - Same Error
function ShowSpecifiedPeriod(pShowPeriod boolean) - Same Error

Please let me know what I am doing wrong here.

View 2 Replies View Related

Pass XML As Parameter To JS Function?

May 25, 2010

I have an XML string which I want to pass to a java script function, where I am displaying that in different window with use of 'window.open()' method, but it is giving error.

View 6 Replies View Related

Set A Variable Name From A Function Parameter

Jul 19, 2009

Is is possible to set a variable name from a function parameter?

Kind of like this but it doesn't work!

View 8 Replies View Related

Pass A Function As A Parameter?

May 30, 2011

I'm adding buttons to my google map through a loop. I pass some parameters, and the addButtons() function creates the buttons. How can I pass the "task" for the button to the function? In the addDomListener line below, I'm now writing the function name literally, I'd like find a way with a parameter.

// The loop...
for (i=0;i<=4;i++) {
oCC = addButtons(aCtrls[i],'btnContainerChild');

[code]...

View 5 Replies View Related

Put The Value Of A Variable Into A Function Parameter

May 26, 2009

I have a JSON array data.cells that I need to iterate through to get the values out of and put the values into an onclick event listener.

Right now the variable name data.cells[i].letter is being based through the buildString function for each cell in my board, instead of the value of the variable. Same goes for the x and y variables.

View 3 Replies View Related

Pass A Parameter To Js Function?

Apr 7, 2010

I have a js file which will open a web site.

Code:

function openurl(url)
<a href =url>Visiting Web!</a>
}

The argument url will be from an input field in a html file.How to implement it?

View 2 Replies View Related

Pass Hash As Function Parameter

Aug 14, 2007

can i pass a hash as a function parameter. ive seen it been used
before but i can't figure out how to do it.

i would like to call a function like this for example

doSomething({variable1:"blabla",variable2:"blabla"});

how would function doSomething be written for this to work.

I would also like the hash to be optional and the variables in the
hash to be optional.
meaning i should also be able to call doSomething(); with no variables
in it.

View 3 Replies View Related

Having Problems Using SetInterval On A Function Which Has A Parameter. Help Please.

Sep 6, 2007

I tried to use setInterval like this but it did not work:

setInterval ( removeitem (theitem)
{
theitem.style.display= "none";
},
1000 );

the function without the setInterval is

function removeitem(theitem)
{
theitem.style.display="none";
}

View 1 Replies View Related

JQuery :: POssible To Pass ID As A Parameter For A Function?

Mar 23, 2011

I've been struggling with a piece of code. I'm guessing the solution is quite simple, but I just can't find it! [code]...

The line that I commented out was an attempt at getting a variable that had the value of the image-id, but it doesn't work.

View 4 Replies View Related

Passing Function Parameter Into GetElementByID?

Oct 3, 2010

I am trying to pass a variable into document.getElementById and it is returning a null value. I am hoping someone can identify my error and point it out. The frustrating thing is, I got it to work and then changed the code and screwed it up again...ugh. Anyways, here is the HTML side of it (an onclick event in a button, calling a function with these arguments):

Code:

<input type="button"
id="AddHeader"
name="Add Header"
value="Add Header"

[Code]....

FireBug shows the problem is with the first line of the function - it's assigning myDiv null instead of what I want it to assign it (div#myDiv1 I think).

View 5 Replies View Related

Getting A Variable To Pass In A Function Parameter?

May 27, 2009

I have a javascript will a) look for a certain value in a drop down box and b) depending on what value is selected open up a div that includes link that when moused over will pop up with an alert box contain the passed parameter. A couple problems with this, one is I am not as sharp on Javascript as I am on PHP, and two, when I manually place a value into the function parameter, if it's a number it works fine, but if its a string or word, it comes up with an undefined error. why the undefined error is coming up only on strings or words?

I am using PHP:

View 5 Replies View Related

Function Parameter Prevents DOMContentLoaded

Dec 29, 2009

I've successfully called a variety of functions that have no parameter value such as: function expand() //expand() in this line is merely an example But I'm unsuccessful calling a function with a paramter value such as: function expand(id) Here is the the call line:

[Code]....

View 8 Replies View Related

Arrays Accepted Into A Parameter Of A Function?

May 13, 2010

I have a question about my array. I have an array called numberarray with 20 elements and i want it to be accepted into a function as a parameter? But i only want the first 10 to be accepted. Does anyone know exactly how i would go about doing this in my function?

View 4 Replies View Related

How To Change Parameter Of OnClick Function

Aug 6, 2010

I have an image with an onclick function and parameters 0, 1. I want to change the parameters of the onclick function through the same function?
<img id="down0" onclick=swap(0,1) />
<javascript>
function swap(a,b){
var imgda=document.getElementById('down'+a);
imgda.onclick = swap(b,b+1);
}
</javascript>
Normally it should change the onclick to swap(1, 2) but it remains 0, 1.

View 2 Replies View Related

Parameter In Function Call Is Not Defined

Nov 22, 2010

I have a good understanding of javascript although I am new to working xml. So I am having a problem getting javascript to recognize that my parameter value in my function call is an attribute in my xml. I called the js function like this:

<a href="#" onClick="ebookCategory(marketing);">Marketing</a>

Here is my js function:

var category;
function ebookCategory(category) {
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
[Code]..

View 3 Replies View Related

Pass A Variable From One Function To Another Using Parameter

Dec 5, 2011

Code:

Can I know how to pass a variable from one function to another using parameter.

The above code seem not working.

View 2 Replies View Related

Pass A Value Using A Parameter In Html (asp) To A Function?

Dec 19, 2011

I am trying to pass a value using a parameter in html (asp) to a javascript function. When I try to pass a value inside of a variable <INPUT type="submit" value="Next Youth" name=button1 onclick="OnButton1(tst);"> it simply doesn't work (no error msg - just nothing) while if I put a value in the call <INPUT type="submit" value="Next Youth" name=button1 onclick="OnButton1('5393');"> it works fine. The javascript looks like this:

function OnButton1(tst)
{
var pth = "youth_edit3.asp?cIndex=" + tst;
document.YouthEdit.action = pth;
document.YouthEdit.submit(); // Submit the page
}

I've set tst = "5393" but it won't work when I try to pass it. Only a literal value of '5393' works.

View 4 Replies View Related

Function Parameter Won't Change Styles

Jun 8, 2009

My script is below

Why wont the Parameter e work in

document.theform.e.style.border="1px solid red";

but it will show the value of e in alert(e) [code]...

View 2 Replies View Related

RegEx - Grab Function Names And Function Parameter Names From A Text Entry

Sep 15, 2005

I am trying to use a regEx to grab Function names and function parameter names from a text entry.

The script is written in javascript and I expect the functions to be in javascript syntax.

For example the code might look like:

Code:
function myFunction1(param1,param2,param3){
some code
}

function myFunction2();

function myFunction3(param);
Whats the best way to accomplish grabbing the function names and parameters?

Should I be breaking it down into multiple regular expressions?

View 5 Replies View Related

Default Function Value From A Cookie

Mar 1, 2006

When my page loads, I check for the existence of a cookie value through
readCookie(). If there is a value present for the cookie, I would like
that to be the default value in function ordering() and that value to
be the SELECTED value in ddlProfileNames. In other words, if there is
no cookie value, then function ordering will default to
ordering("Div1,Div2,Div3,Div4"). If there is a value, then that should
be used in function ordering and as the default value in
ddlProfileNames. Thanks for any help.

<body onLoad="readCookie('default')">

<FORM name="frmProfileNames">
<SELECT class="smalltext" id="ddlProfileNames"
onChange="ordering(this.options[this.selectedIndex].value);">
<option value="Div1,Div2">1 & 2</option>
<option value="Div3,Div4">3 & 4</option>
<option value="Div1,Div2,Div3,Div4" SELECTED>All Sections</option>
</SELECT>
<a href="#" onclick="setCookie('default', 30);return false">Save as
Default Profile</a>
</FORM>

<SCRIPT>
function ordering(sorder)
{
// code here
}

// start things off:
ordering("Div1,Div2,Div3,Div4");

</SCRIPT>

View 1 Replies View Related







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