Connecting Tech Pros Worldwide Forums | Help | Site Map

Boolean Function Parameter

Matt
Guest
 
Posts: n/a
#1: Jul 23 '05
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. Thanks.


Matt
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Boolean Function Parameter


Figured it out.... I needed to pass the boolena value as a literal
string so I placed double quotes around the boolean value and single
quotes around the parameter.

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

Grant Wagner
Guest
 
Posts: n/a
#3: Jul 25 '05

re: Boolean Function Parameter


"Matt" <matt_marshall@manning-napier.com> wrote in message
news:1121708390.332500.284920@g43g2000cwa.googlegr oups.com...[color=blue]
> Figured it out.... I needed to pass the boolena value as a literal
> string so I placed double quotes around the boolean value and single
> quotes around the parameter.
>
> onclick="ShowSpecifiedPeriod('<%If bShowPeriod = false then
> Response.Write "true" else Response.Write "false"%>')"[/color]

Since you can't pass a "boolean value" on a URL at all (all you are
passing are the string "true" or the string "false" which then have
special meaning to the server-side processing), I usually pass either 0
or 1. It is shorter (if the resulting server request is a GET) and it is
much easier to deal with on the server (using server-side JavaScript in
this case):

var bShowPeriod = (1 == +Request.value('ShowPeriod'));

--
Grant Wagner <gwagner@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


Closed Thread