Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Optional Parameters in Function

Status
Not open for further replies.

bdichiara

Programmer
Oct 11, 2006
206
US
I have a function :
Code:
function setSource(filename,caption,larger){
  ...

How do i set the default of larger to "false" when the function is used without the variable? in other words, i want the "larger" variable to be optional.

_______________
_brian.
 
Here's a quick-n-easy example:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]

<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

function blah(a, b) {
   b = (typeof(b) == "undefined") ? false : b;
   alert(b);
}

window.onload = function () {
   blah(1, 2);
   blah(1);
};

</script>
<style type="text/css"></style>
</head>

<body>
</body>
</html>

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
[purple]Glad I could help[/purple] [wink]

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top