putting ASP variable into JS variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • middletree

    putting ASP variable into JS variable

    I am mixing ASP/VBScript with client-side Javascript, and part of it works,
    and part does not. But both parts are coded practically the same, so I don't
    see what I am doing wrong.

    First, I do some ASP to get my page name and put it into an ASP variable
    called strPageName. I verified that this part is working correctly, by doing
    a response.write of strPageName.

    Next, I needed to populate a couple of Javascript variables:
    <script type='text/javascript'>
    var strPageName = "<%=strPageName %>";
    var strTicketID = "<%=strTicketID %>";
    </script>

    So then, I should point out that I have some javascript code which builds a
    menu. Very good code when it's static, but I'm trying to make it dynamic.

    If I am on one of two pages, I want it to show 5 main menu items. Otherwise,
    just 4 of them. Here's where it's breaking. I only see 4 menu items, even
    when it's on the pages in question. I tried it on several pages, and it
    shows up exactly the same no matter what. And no error messages as far as I
    can tell.

    Here's the code to make that 5th menu item, as well as its submenu items,
    show up:

    =============== ==============
    //above this is the part that builds the first 3 main items

    Menu4=new Array("ARGOMEDI A","http://argomedia","",0 );

    if (strPageName == "DisplayFullTic ketInfo.asp")
    {
    Menu4=new Array("This Ticket","","",6 );
    Menu4_1=new Array("Add To This
    Ticket","AddToT icket.asp?Ticke tID="+strTicket ID,"",0,20,150) ;
    Menu4_2=new Array("Edit This
    Ticket","Ticket Log.asp?TicketI D="+strTicketID +"&New=notnew", "",0);
    Menu4_3=new Array("Go To Latest History
    Item","DisplayF ullTicketInfo.a sp?TicketID="+s trTicketID+"#la test","",0);
    Menu4_4=new Array("Printabl e--All
    notes","Display FullTicketInfo. asp?Print=Yes&T icketID="+strTi cketID,"",0);
    Menu4_5=new Array("Printabl e--No Internal
    notes","Display FullTicketInfo. asp?Print=Yes&T icketID="+strTi cketID+"&Intern a
    l=no","",0);
    Menu4_6=new Array("Printabl e--No External
    notes","Display FullTicketInfo. asp?Print=Yes&T icketID="+strTi cketID+"&Extern a
    l=no","",0);

    Menu5=new Array("ARGOMEDI A","http://argomedia","",0 );
    }

    if (strPageName == "AddToTicket.as p")
    {
    Menu4=new Array("This Ticket","","",2 );
    Menu4_1=new Array("Edit This
    Ticket","Ticket Log.asp?TicketI D="+strTicketID +"&New=notnew", "",0);
    Menu4_2=new
    Array("Bottom", "AddToTicket.as p?TicketID="+st rTicketID+"#lat est","",0);

    Menu5=new Array("ARGOMEDI A","http://argomedia","",0 );
    }
    =============== ==============

    So the problem is that the IF statement doesn't seem to take. In other
    words, it acts like it's not on AddToTicket.asp or
    DisplayFullTick etInfo.asp, when it clearly is.
    I am sure I have a minor syntax problem, so if anyone can spot my error, I
    would appreciate it.

    I should also add that this is for an Intranet app, and all users are on IE
    5 or higher



  • Erwin Moller

    #2
    Re: putting ASP variable into JS variable

    middletree wrote:
    [color=blue]
    > =============== ==============
    > //above this is the part that builds the first 3 main items[/color]

    alert ("before first if: strPageName = "+strPageNa me);
    [color=blue]
    >
    > Menu4=new Array("ARGOMEDI A","http://argomedia","",0 );
    >
    > if (strPageName == "DisplayFullTic ketInfo.asp")
    > {
    > Menu4=new Array("This Ticket","","",6 );
    > Menu4_1=new Array("Add To This
    > Ticket","AddToT icket.asp?Ticke tID="+strTicket ID,"",0,20,150) ;
    > Menu4_2=new Array("Edit This
    > Ticket","Ticket Log.asp?TicketI D="+strTicketID +"&New=notnew", "",0);
    > Menu4_3=new Array("Go To Latest History
    > Item","DisplayF ullTicketInfo.a sp?TicketID="+s trTicketID+"#la test","",0);
    > Menu4_4=new Array("Printabl e--All
    > notes","Display FullTicketInfo. asp?Print=Yes&T icketID="+strTi cketID,"",0);
    > Menu4_5=new Array("Printabl e--No Internal
    >[/color]
    notes","Display FullTicketInfo. asp?Print=Yes&T icketID="+strTi cketID+"&Intern a[color=blue]
    > l=no","",0);
    > Menu4_6=new Array("Printabl e--No External
    >[/color]
    notes","Display FullTicketInfo. asp?Print=Yes&T icketID="+strTi cketID+"&Extern a[color=blue]
    > l=no","",0);
    >
    > Menu5=new Array("ARGOMEDI A","http://argomedia","",0 );
    > }[/color]

    alert ("before second if: strPageName = "+strPageNa me);

    [color=blue]
    >
    > if (strPageName == "AddToTicket.as p")
    > {
    > Menu4=new Array("This Ticket","","",2 );
    > Menu4_1=new Array("Edit This
    > Ticket","Ticket Log.asp?TicketI D="+strTicketID +"&New=notnew", "",0);
    > Menu4_2=new
    > Array("Bottom", "AddToTicket.as p?TicketID="+st rTicketID+"#lat est","",0);
    >
    > Menu5=new Array("ARGOMEDI A","http://argomedia","",0 );
    > }
    > =============== ==============
    >
    > So the problem is that the IF statement doesn't seem to take. In other
    > words, it acts like it's not on AddToTicket.asp or
    > DisplayFullTick etInfo.asp, when it clearly is.
    > I am sure I have a minor syntax problem, so if anyone can spot my error, I
    > would appreciate it.
    >
    > I should also add that this is for an Intranet app, and all users are on
    > IE 5 or higher[/color]


    What does it alert with?

    Comment

    • Guest's Avatar

      #3
      Re: putting ASP variable into JS variable


      Erwin Moller wrote:[color=blue]
      >alert ("before first if: strPageName = "+strPageNa me);
      >What does it alert with?[/color]

      Well, good news and bad news. Being a JS novice, I didn't know of a good
      way to do the JS equivalent of response.write, and you showed me, and it
      helped me solve my original problem. (I had defined strPageName as the page
      name PLUS "<br>". I took that last part out and it works smoothly. On one
      page. For some reason, I am getting an error on the other page.

      Here's my code:

      =============== =============== ===========
      Menu4=new Array("ARGOMEDI A","http://argomedia","",0 );

      if (strPageName == "DisplayFullTic ketInfo.asp")
      {
      Menu4=new Array("This Ticket","","",6 );
      Menu4_1=new Array("Add To This Ticket","AddToT icket.asp?Ticke tID="+strTicket ID,"",0,20,150) ;
      Menu4_2=new Array("Edit This Ticket","Ticket Log.asp?TicketI D="+strTicketID +"&New=notnew", "",0);
      Menu4_3=new Array("Go To Latest History Item","DisplayF ullTicketInfo.a sp?TicketID="+s trTicketID+"#la test","",0);
      Menu4_4=new Array("Printabl e--All notes","Display FullTicketInfo. asp?Print=Yes&T icketID="+strTi cketID,"",0);
      Menu4_5=new Array("Printabl e--No Internal notes","Display FullTicketInfo. asp?Print=Yes&T icketID="+strTi cketID+"&Intern al=no","",0);
      Menu4_6=new Array("Printabl e--No External notes","Display FullTicketInfo. asp?Print=Yes&T icketID="+strTi cketID+"&Extern al=no","",0);

      Menu5=new Array("ARGOMEDI A","http://argomedia","",0 );
      }

      if (strPageName == "AddToTicket.as p")
      {
      Menu4=new Array("This Ticket","","",2 );
      Menu4_1=new Array("Edit This Ticket","Ticket Log.asp?TicketI D="+strTicketID +"&New=notnew", "",0);
      Menu4_2=new Array("Bottom", "AddToTicket.as p?TicketID="+st rTicketID+"#lat est","",0);

      Menu5=new Array("ARGOMEDI A","http://argomedia","",0 );
      }
      =============== =============== ============

      You'll see that if I am on the Full page, I display 6 submenu items, and
      if I am on the Add page, only 2 submenu items. All other pages don't show
      this main menu item at all. Well, the other pages work. The Full page works.
      But the Add page doesn't.

      I get an error that says invalid argument, and gives me a line number, but
      it doesn't correspond with anything. Probably because this is an external
      js inside of an include file.

      I don't understand why the Full works and the Add doesn't, as they are virtually
      the same. I am sure it is something simple, like a missed semicolon or extra
      quote. Any insights gained by observations of those JS experts with an eagle
      eye would be appreciated.

      Comment

      • Erwin Moller

        #4
        Re: putting ASP variable into JS variable

        Hi Middletree,

        I cannot see an error in your second if-statement.
        But then again, you create on arrays there, with nice names, but only
        arrays.
        I do not know what you do with the arrays you just created.

        My advise is this:
        Instead of including your JS-code, plase just paste it on the same page.
        After that you can track the error to the corresponding line on your page,
        and maybe you can see what goes wrong.

        And always: If you are stuck, start inserting alert() statements, and let
        them alert to you what is going on. I debug all my scripts with alerts.


        Good luck,
        Erwin Moller

        Comment

        Working...