Pass Boolean Parameter to JS Function

Discussion in 'ASP General' started by Matt, Jul 18, 2005.

  1. Matt

    Matt Guest

    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.
     
    Matt, Jul 18, 2005
    #1
    1. Advertising

  2. 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


    "Matt" <> wrote in message
    news:...
    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.
     
    Ray Costanzo [MVP], Jul 18, 2005
    #2
    1. Advertising

  3. Try:

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

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



    "Matt" <> wrote in message
    news:...
    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.
     
    Aaron Bertrand [SQL Server MVP], Jul 18, 2005
    #3
  4. Matt

    Steven Burn Guest

    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)

    "Matt" <> wrote in message
    news:...
    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.
     
    Steven Burn, Jul 18, 2005
    #4
  5. Of course, I was thinking about the wrong set of quotes, not the case
    sensitivity...



    "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
    message news:%...
    > 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
    >
    >
    > "Matt" <> wrote in message
    > news:...
    > 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.
    >
    >
     
    Aaron Bertrand [SQL Server MVP], Jul 18, 2005
    #5
  6. Matt

    Matt Guest

    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.
     
    Matt, Jul 18, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J Leonard
    Replies:
    4
    Views:
    12,891
    Mark Space
    Jan 19, 2008
  2. Matt

    Boolean Function Parameter

    Matt, Jul 18, 2005, in forum: Javascript
    Replies:
    2
    Views:
    127
    Grant Wagner
    Jul 25, 2005
  3. AzamSharp
    Replies:
    2
    Views:
    201
  4. soni2926
    Replies:
    4
    Views:
    123
    William James
    Nov 21, 2008
  5. Metre Meter
    Replies:
    7
    Views:
    462
    Metre Meter
    Aug 6, 2010
Loading...

Share This Page