Prevent error message with optional JavaScript Parameter?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Prevent error message with optional JavaScript Parameter?

Post by JAB Creations »

I'd like to have an optional third parameter though I don't want the error console complaining when it does not exist, how do I handle an undefined parameter in such a situation? I have trued to return, return true, return false, and null though since none of them worked I presume the extent of my know-how has run out. :mrgreen:

My JavaScript looks like this...

Code: Select all

function ajax2(name3up,name2up,name1up){if (name1up == undefined) {null;}}
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Prevent error message with optional JavaScript Parameter?

Post by JAB Creations »

Figured it out. :mrgreen:

Code: Select all

function ajax2(name3up,name2up,name1up) { // place at the END of the script!if (typeof name1up == "undefined") {return;}}
If 'name1up' is set and you use it it won't be "undefined" so there should be no error spawned either way. :)
Post Reply