Pass Boolean Parameter to JS Function

M

Matt

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(pShowPerio­d){
document.mfperformance.ShowPer­iod.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(pShowPerio­d boolean) - Same Error


Please let me know what I am doing wrong here. Thanks.
 
R

Ray Costanzo [MVP]

Javascript is case sensitive. Since you're telling VBScript to
Response.Write True or False, it will write it as it seems fit -
capitalized. Use literal strings when you Response.Write stuff:

<% If bShowPeriod Then Response.Write "false" Else Response.Write "true" %>

Do you really mean to have "If true then false, and if false then true?"

Ray at work


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(pShowPerio­d){
document.mfperformance.ShowPer­iod.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(pShowPerio­d boolean) - Same Error


Please let me know what I am doing wrong here. Thanks.
 
A

Aaron Bertrand [SQL Server MVP]

Try:

onclick="ShowSpecifiedPeriod('<%= not bShowPeriod %>');"

Note the quotes around the value. Otherwise, JS will expect a variable name
(which you have not defined)...



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(pShowPerio­d){
document.mfperformance.ShowPer­iod.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(pShowPerio­d boolean) - Same Error


Please let me know what I am doing wrong here. Thanks.
 
S

Steven Burn

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

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

::: Declaration :::

Ur I.T. Mate Group is NOT a company, it is a non-commercial and not for
profit collection of websites developed and maintained by Steven Burn.

Websites and domains currently owned by Ur I.T. Mate Group are provided on a
free to view and use basis. Ur I.T. Mate Group does not and will not ask for
or solicit, personal information*, password, credit card details or
payments. For more information, please see our Privacy Policy.

Ur I.T. Mate Group and Steven Burn (CEO) are based in the United Kingdom.

* Except where registration for an online service is required (e.g. forums,
sGB)

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(pShowPerio­d){
document.mfperformance.ShowPer­iod.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(pShowPerio­d boolean) - Same Error


Please let me know what I am doing wrong here. Thanks.
 
A

Aaron Bertrand [SQL Server MVP]

Of course, I was thinking about the wrong set of quotes, not the case
sensitivity...
 
M

Matt

Great. Thank you very much. Using the literal string worked great. Yes
I do want if true then false and if false then true. I want the button
option to be different than the actual option. Otherwise when the user
invokes the onClcik event I will always be passing the same boolean
value. The JS function will submit the form and the "ShowPeriod" is a
hidden form field that I use. Initially the screen will not paint a
portion until the user clicks the biton to show the remainder of the
screen. Then if they also need to ability to hide it. Thanks.

I did try with the single quotes (around the parameter) and without
them before but it was the double quotes around the true and false that
did.

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

Thank you very much for your posts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top