Var Assignment.

Discussion in 'ASP General' started by n2K, Jan 31, 2005.

  1. n2K

    n2K Guest

    I have a var in a javascript like so:
    <script language="javascript">

    var timerID = null;
    var timerRunning = false;
    var timeIncrement = 0;
    LATER in the code I need to assign a session var to the local var like
    so....

    timeIncrement = session("incTime")

    How do I do this?

    I keep getting errors like "an exception of type MS jscript runtime...
    Object expected was not handled"

    tx,

    NB
    n2K, Jan 31, 2005
    #1
    1. Advertising

  2. n2K

    Evertjan. Guest

    n2K wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:

    > timeIncrement = session("incTime")
    >
    > How do I do this?
    >


    You cannot mix serverside and clientside code that way.

    timeIncrement = '<% = session("incTime") %>'

    mind the [single] quotes

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Jan 31, 2005
    #2
    1. Advertising

  3. n2K

    n2K Guest

    Been there tried that. What happens is the STRING '<% = session("incTime")
    %>' is assigned to timeIncrement!

    ???

    "Evertjan." <> wrote in message
    news:Xns95EF7FEF85682eejj99@194.109.133.29...
    > n2K wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
    >
    >> timeIncrement = session("incTime")
    >>
    >> How do I do this?
    >>

    >
    > You cannot mix serverside and clientside code that way.
    >
    > timeIncrement = '<% = session("incTime") %>'
    >
    > mind the [single] quotes
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Replace all crosses with dots in my emailaddress)
    >
    n2K, Jan 31, 2005
    #3
  4. n2K

    Evertjan. Guest

    n2K wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
    > "Evertjan." <> wrote in message
    > news:Xns95EF7FEF85682eejj99@194.109.133.29...
    >> n2K wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
    >>
    >>> timeIncrement = session("incTime")
    >>>
    >>> How do I do this?
    >>>

    >>
    >> You cannot mix serverside and clientside code that way.
    >>
    >> timeIncrement = '<% = session("incTime") %>'
    >>
    >> mind the [single] quotes


    > Been there tried that. What happens is the STRING '<% =
    > session("incTime") %>' is assigned to timeIncrement!
    >
    > ???


    [please do not toppost on usenet]

    Not true, if used in an .asp file on an asp server.

    If you don't use ASP, why post here?

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Jan 31, 2005
    #4
  5. So leave out the quotes,

    timeIncrement = <% = session("incTime") %>

    or do an explicit type conversion.

    Bob Barrows

    n2K wrote:
    > Been there tried that. What happens is the STRING '<% =
    > session("incTime") %>' is assigned to timeIncrement!
    >
    > ???
    >
    > "Evertjan." <> wrote in message
    > news:Xns95EF7FEF85682eejj99@194.109.133.29...
    >> n2K wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
    >>
    >>> timeIncrement = session("incTime")
    >>>
    >>> How do I do this?
    >>>

    >>
    >> You cannot mix serverside and clientside code that way.
    >>
    >> timeIncrement = '<% = session("incTime") %>'
    >>
    >> mind the [single] quotes
    >>
    >> --
    >> Evertjan.
    >> The Netherlands.
    >> (Replace all crosses with dots in my emailaddress)


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Jan 31, 2005
    #5
  6. Bob Barrows [MVP] wrote:
    > So either leave out the quotes,
    >
    > timeIncrement = <%= session("incTime") %>
    >
    > or do an explicit type conversion.
    >

    .... in your client-side code, not inside the server-side brackets

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Jan 31, 2005
    #6
  7. n2K

    n2K Guest

    Regardless how I try this, the <% and %> do not appear in the typical
    hilight Yellow color!

    "Bob Barrows [MVP]" <> wrote in message
    news:...
    > So leave out the quotes,
    >
    > timeIncrement = <% = session("incTime") %>
    >
    > or do an explicit type conversion.
    >
    > Bob Barrows
    >
    > n2K wrote:
    >> Been there tried that. What happens is the STRING '<% =
    >> session("incTime") %>' is assigned to timeIncrement!
    >>
    >> ???
    >>
    >> "Evertjan." <> wrote in message
    >> news:Xns95EF7FEF85682eejj99@194.109.133.29...
    >>> n2K wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
    >>>
    >>>> timeIncrement = session("incTime")
    >>>>
    >>>> How do I do this?
    >>>>
    >>>
    >>> You cannot mix serverside and clientside code that way.
    >>>
    >>> timeIncrement = '<% = session("incTime") %>'
    >>>
    >>> mind the [single] quotes
    >>>
    >>> --
    >>> Evertjan.
    >>> The Netherlands.
    >>> (Replace all crosses with dots in my emailaddress)

    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
    n2K, Jan 31, 2005
    #7
  8. n2K

    n2K Guest

    Actually it is true, I've added watches and it is assigned theString value.
    And yes, in an ASP page on an ASP server. Not trying to be difficult, simply
    laying out what results I am getting.

    n2k

    "Evertjan." <> wrote in message
    news:Xns95EF85375E3F5eejj99@194.109.133.29...
    > n2K wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
    >> "Evertjan." <> wrote in message
    >> news:Xns95EF7FEF85682eejj99@194.109.133.29...
    >>> n2K wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:
    >>>
    >>>> timeIncrement = session("incTime")
    >>>>
    >>>> How do I do this?
    >>>>
    >>>
    >>> You cannot mix serverside and clientside code that way.
    >>>
    >>> timeIncrement = '<% = session("incTime") %>'
    >>>
    >>> mind the [single] quotes

    >
    >> Been there tried that. What happens is the STRING '<% =
    >> session("incTime") %>' is assigned to timeIncrement!
    >>
    >> ???

    >
    > [please do not toppost on usenet]
    >
    > Not true, if used in an .asp file on an asp server.
    >
    > If you don't use ASP, why post here?
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Replace all crosses with dots in my emailaddress)
    >
    n2K, Jan 31, 2005
    #8
  9. n2K

    n2K Guest

    Perhaps if I include the entire code snippet, it may help.

    SNIPPET BEGINS

    <script language="javascript">

    function startclock() {
    stopclock();
    timeValue = '<%=session("timerInc")%>';
    timerID = setInterval("increment()", timeValue);
    timerRunning = true;
    document.images.bar.src=image00.src;
    }
    </script>

    SNIPPET END

    Thanks
    n2k

    "n2K" <> wrote in message
    news:e9TD$...
    >I have a var in a javascript like so:
    > <script language="javascript">
    >
    > var timerID = null;
    > var timerRunning = false;
    > var timeIncrement = 0;
    > LATER in the code I need to assign a session var to the local var like
    > so....
    >
    > timeIncrement = session("incTime")
    >
    > How do I do this?
    >
    > I keep getting errors like "an exception of type MS jscript runtime...
    > Object expected was not handled"
    >
    > tx,
    >
    > NB
    >
    >
    n2K, Jan 31, 2005
    #9
  10. n2K wrote:
    > Regardless how I try this, the <% and %> do not appear in the typical
    > hilight Yellow color!
    >

    Not for me either in a script block (assuming you are using Interdev). The
    yellow-highlight is only applied in the html area. Ignore the lack of
    highlighting. It works even though Interdev does not recognize it.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Jan 31, 2005
    #10
  11. n2K

    n2K Guest

    Of course you are right. Don't know what I was thinking.

    n2k
    "Bob Barrows [MVP]" <> wrote in message
    news:%...
    > n2K wrote:
    >> Regardless how I try this, the <% and %> do not appear in the typical
    >> hilight Yellow color!
    >>

    > Not for me either in a script block (assuming you are using Interdev). The
    > yellow-highlight is only applied in the html area. Ignore the lack of
    > highlighting. It works even though Interdev does not recognize it.
    >
    > Bob Barrows
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
    n2K, Jan 31, 2005
    #11
  12. n2K wrote:
    > Perhaps if I include the entire code snippet, it may help.
    >
    > SNIPPET BEGINS
    >
    > <script language="javascript">
    >
    > function startclock() {
    > stopclock();
    > timeValue = '<%=session("timerInc")%>';


    As I said before, if you want timeValue to be a number, either get rid of
    the quotes

    timeValue = <%=session("timerInc")%>;

    Or use a conversion function on the variable to convert it to a number. The
    unary + operator can be used for this:
    > timeValue = '<%=session("timerInc")%>';
    > timerID = setInterval("increment()", +timeValue);
    > timerRunning = true;
    > document.images.bar.src=image00.src;
    > }
    > </script>
    >


    Look at the page's source after running it (comment out the setInterval
    statement) to see what is happening

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Jan 31, 2005
    #12
  13. n2K

    n2K Guest

    Bob, I tried to remove the quotes as you had previouslsy mentioned and I
    still get the same error.

    n2k
    "Bob Barrows [MVP]" <> wrote in message
    news:...
    > n2K wrote:
    >> Perhaps if I include the entire code snippet, it may help.
    >>
    >> SNIPPET BEGINS
    >>
    >> <script language="javascript">
    >>
    >> function startclock() {
    >> stopclock();
    >> timeValue = '<%=session("timerInc")%>';

    >
    > As I said before, if you want timeValue to be a number, either get rid of
    > the quotes
    >
    > timeValue = <%=session("timerInc")%>;
    >
    > Or use a conversion function on the variable to convert it to a number.
    > The
    > unary + operator can be used for this:
    >> timeValue = '<%=session("timerInc")%>';
    >> timerID = setInterval("increment()", +timeValue);
    >> timerRunning = true;
    >> document.images.bar.src=image00.src;
    >> }
    >> </script>
    >>

    >
    > Look at the page's source after running it (comment out the setInterval
    > statement) to see what is happening
    >
    > Bob Barrows
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
    n2K, Jan 31, 2005
    #13
  14. I don't rememeber the mentioning of an error... oh! the "object expected"
    error? Can you post the page's source?

    Are you sure the problem isn't the increment() function? Does it work if you
    hard-code a numeric value into timeValue rather than using the
    response.write?

    Let me try to duplicate this ... nope - it works fine for me. I think the
    issue is elsewhere.

    Bob Barrows

    n2K wrote:
    > Bob, I tried to remove the quotes as you had previouslsy mentioned
    > and I still get the same error.
    >
    > n2k
    > "Bob Barrows [MVP]" <> wrote in message
    > news:...
    >> n2K wrote:
    >>> Perhaps if I include the entire code snippet, it may help.
    >>>
    >>> SNIPPET BEGINS
    >>>
    >>> <script language="javascript">
    >>>
    >>> function startclock() {
    >>> stopclock();
    >>> timeValue = '<%=session("timerInc")%>';

    >>
    >> As I said before, if you want timeValue to be a number, either get
    >> rid of the quotes
    >>
    >> timeValue = <%=session("timerInc")%>;
    >>
    >> Or use a conversion function on the variable to convert it to a
    >> number. The
    >> unary + operator can be used for this:
    >>> timeValue = '<%=session("timerInc")%>';
    >>> timerID = setInterval("increment()", +timeValue);
    >>> timerRunning = true;
    >>> document.images.bar.src=image00.src;
    >>> }
    >>> </script>
    >>>

    >>
    >> Look at the page's source after running it (comment out the
    >> setInterval statement) to see what is happening
    >>
    >> Bob Barrows
    >> --
    >> Microsoft MVP -- ASP/ASP.NET
    >> Please reply to the newsgroup. The email account listed in my From
    >> header is my spam trap, so I don't check it very often. You will get
    >> a quicker response by posting to the newsgroup.


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Jan 31, 2005
    #14
    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. Alvin Bruney

    Threads.. Session var lost, App var ok

    Alvin Bruney, Dec 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    357
    rooster575
    Dec 2, 2003
  2. thomson
    Replies:
    10
    Views:
    2,490
    Eliyahu Goldin
    Jun 20, 2005
  3. thomson
    Replies:
    0
    Views:
    377
    thomson
    Jun 20, 2005
  4. Fred
    Replies:
    3
    Views:
    324
    Alf P. Steinbach
    Aug 10, 2003
  5. Alex Vinokur
    Replies:
    4
    Views:
    472
    Ron Natalie
    Sep 24, 2003
Loading...

Share This Page