473,394 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Optional param in a javascript fct

Hello everybody. I'm trying to use an optional parameters in a
javascript function and don't succeed.

If I believe in the page at <http://www.mozilla.org/js/language/js20-
2002-
04/core/functions.html#N-Parameter>, it's possible at least in
Javascript 2.0 (don't know for the others versions).

Here is what I do :

<script language="JavaScript"><!--
function Test(a,b=100){alert("a=" & a & ", b=" & b);}
//--></script>

And, too, with <script language="JavaScript2.0">.

And it doesn't work. The javascript console binded with Mozilla indicate
the "=" as being an error, telling it wait a ")" after the formal
parameters

I've tried differents syntax too, without success(example : function
Test(a,b:Integer=100)).

How to proceed ? And, do these optional params specific to javascript
2.0 ?
Jul 23 '05 #1
7 3250
On 10/07/2005 15:33, JellyON wrote:
I'm trying to use an optional parameters in a javascript function and
don't succeed.


Optional arguments are not implemented in current browsers. However, you
can produce the same effect yourself:

function Test(a, b) {
if('undefined' == typeof b) {b = 100;}

/* ... */
}

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jul 23 '05 #2


JellyON wrote:

If I believe in the page at <http://www.mozilla.org/js/language/js20-
2002-
04/core/functions.html#N-Parameter>, it's possible at least in
Javascript 2.0 (don't know for the others versions).


JavaScript 2.0 is a design but so far not a language implemented in
existing browsers.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3
VK
> Here is what I do :
<script language="JavaScript"><!--
function Test(a,b=100){alert("a=" & a & ", b=" & b);}
//--></script>


What mf did learn you to do such things any way? Even Bezerkly system
doesn't imply it. What school are you from? Street mf's society?

Jul 23 '05 #4
In article <42***********************@newsread4.arcor-online.net>,
ma*******@yahoo.de says...


JellyON wrote:

If I believe in the page at <http://www.mozilla.org/js/language/js20-
2002-
04/core/functions.html#N-Parameter>, it's possible at least in
Javascript 2.0 (don't know for the others versions).


JavaScript 2.0 is a design but so far not a language implemented in
existing browsers.


Oups ! I better understand now. Thanks
Jul 23 '05 #5
In article <GB******************@text.news.blueyonder.co.uk >,
m.******@blueyonder.co.uk says...
On 10/07/2005 15:33, JellyON wrote:
I'm trying to use an optional parameters in a javascript function and
don't succeed.


Optional arguments are not implemented in current browsers. However, you
can produce the same effect yourself:

function Test(a, b) {
if('undefined' == typeof b) {b = 100;}

/* ... */
}

[snip]

Mike


Nice, i'll go this way. Thanks a lot Mike
Jul 23 '05 #6
In article <11**********************@o13g2000cwo.googlegroups .com>,
sc**********@yahoo.com says...
Here is what I do :
<script language="JavaScript"><!--
function Test(a,b=100){alert("a=" & a & ", b=" & b);}
//--></script>


What mf did learn you to do such things any way? Even Bezerkly system
doesn't imply it. What school are you from? Street mf's society?


Simply not used to use javascript, but open minded, anyway ;-)
Jul 23 '05 #7
VK
sorry, it was a bad day I guess.

Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Adam Dyga | last post by:
Hi, How to create function with optional parameter passed by reference? I've tried sth like this: function (&$param=NULL) // or: function (&$param=new array()) { //... }
5
by: Keeko | last post by:
Actionscriptor needs help! I have a working javascript function (getVar()) that extracts a variable from a link and returns it. (tested with alert() works fine). But I am unsure of how to right...
13
by: William Ryan | last post by:
I just picked up a copy of John Robbins' debugging book and started to look at disassembled code. Anyway, I hate optional Parameters in VB, but I was checking them out to see what IL is created. ...
4
by: Yong Jiang | last post by:
I am trying to convert some vb code calling COM oboject methods to C#. Example shown as follows Dim Stream As New ADODB.Stream Call Stream.Open() Stream.Open has three optional parameters. ...
21
by: Marc DVer | last post by:
I am trying to create a query that can be loaded as a querydef object but not having to assign values to the parameters if I don't want to. Normally when using a parameter query in VBA my code...
2
by: siliconpiNOSPAM | last post by:
Hi, I'm writing a program that should accept the following parameters: XMLfile (required) Logfile (required) /A (append flag, optional) /D 123 (delay value, optional, but # should follow /D...
2
by: Ross | last post by:
Hi folks This is just a general question. Suppose I have a SP that has several params and this includes one optional param. If I have all the params as args for the WS, and suppose for a...
3
by: guy | last post by:
found this oddity- copying a vb6 function with optional parameters and pasting it into a vb2003 class, for conversion purposes, it all works fine except that the collapsing "-" on the LHS goes...
7
by: Sam Shrefler | last post by:
I'm working on creating a WebService / WebMethod to receive a record in real time from another system. The record contains about 20 fields. 10 of which aren't required. I was planning on just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.