Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript ASP Page: Custom Function Is Not Defined

    I apologize if this is a bit general or high-level, but I'm stumped and don't know what to do. I've created a function that works fine under straight JavaScript, but fails when used in an ASP context.

    I've researched JavaScript in ASP pages and the syntax seems to be correct. I don't know what to do to resolve this. I see an error in the JavaScript Console that tells me the "helpdesk" function is undefined.

    I have four menu buttons that are keyed to execute this function onClick. Here's one example of a button:

    <CODE><INPUT TYPE=image NAME="DBNHD" SRC="DBButton.jpg" BORDER=0 ONCLICK="helpdesk('DB')"></CODE>

    The function, "helpdesk", is supposed to check the value of the menu button against switch cases and then adjust the look of the page depending on the group selected. "Helpdesk" also calls an "updates" function that hides or reveals Response.Write statements that display group-specific information.

    The following scripting is defined in the header, and I am using a <%@ LANGUAGE="JavaScript"%> tag at the top of my code.

    Help will be greatly appreciated.

    <%
    var menu;
    var contract;

    var DBConn = Server.CreateObject("ADODB.Connection");
    DBConn.Open(Application("HDNewsConnStr"));
    var UpdateRecord = Server.CreateObject("ADODB.Recordset");
    var SQLQuery = "SELECT DBRecent.UserID, DBRecent.Subject, DBRecent.Update, DBRecent.Affected, DBRecent.Actions, DBRecent.Info, DBRecent.Date, DBRecent.Time FROM DBRecent;";
    UpdateRecord.Open(SQLQuery, DBConn);

    function helpdesk (group) {var archive;
    var defmsg = document.getElementById("defdisplay");
    var update = document.getElementById("updtdisplay");
    if (menu != null && menu != "default") {menu.style.display = "none"};
    switch (group) {case "DB":
    contract = "DB";
    menu = document.getElementById("DB");
    archivet = "Dressbarn Archive";
    break;
    case "FAI":
    menu = document.getElementById("FAI");
    contract = "FAI";
    archivet = "FAI Archive";
    break;
    case "FNC":
    menu = document.getElementById("FNC");
    contract = "FNC";
    archivet = "FNC Archive";
    break;
    case "MIS":
    menu = document.getElementById("MIS");
    contract = "MIS";
    archivet = "MIS Archive";
    break};
    if (menu != null && menu != "default") {menu.style.display = ""};
    if (contract != null && contract != "default") {updates(true)}
    else {updates(false)};
    var archive = document.getElementById("archiveheader");
    archive.childNodes[0].nodeValue = archivet};

    function updates (state) {var defmsg = document.getElementById("defdisplay");
    var update = document.getElementById("updtdisplay");
    if (state == true) {defmsg.style.display = "none"; update.style.display = ""}
    else {defmsg.style.display = "table-row"; update.style.display = "none"}}
    %>

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Everything between <% and %> is server-side. It seems you want client side action to take place. The functions are no longer available to you once the page has been served. Move the functions to the <script></script> tags and see if that gives you the functionality you want.

    BaldEagle

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I need to pass the value for the variable "contract" from the JavaScript to the ASP in order to change the information displayed.

    This page is designed to be a "Hot News" page for my Helpdesk staff. We have four contracts that receive separate updates. For ease of use, I've created a database and input form for my team leads to add updates. The most recent update is then displayed on a contract-specific basis.

    Any guidance here would be helpful. This stuff is driving me nuts. Every time I fix one function I break another. It seems there are dozens of different opinions on ASP and JavaScript syntax, and at least five different ways to correctly write each function.

    I miss the days of structured programming languages.

  • #4
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What i have in mind is creating a hidden field.
    When s.o click a button, javascript will copy value to that field and submit for asp to process.

  • #5
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Gavric
    I need to pass the value for the variable "contract" from the JavaScript to the ASP in order to change the information displayed.
    I am not sure what you mean by this statement. As you have it written now the javascript is your ASP. Sort of anyway, as I stated before, it will not do what you want because you are looking for client side manipulation. When the button is clicked there is no function to call. All the code between the <%%> was run on the server prior to serving the page to the client and that code does not get sent with the page. On the client side you can change the display as you wish based on the value passed into the function(s), but the function(s) will need to be inside <script></script> tags so that the client has access to it. Your code doesn't seem to be the issue, but the way you are implementing is.

    BaldEagle

  • #6
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Your code will not work on server side jscript because there is no document object in server side jscript, it is only a part of client side javascript/jscript.

    as Bald eagle stated you have to remember that asp is finished long before any events like the clicking of a button, or the selection of a dropdown are triggered by the user. You can add a clientside function to trigger a postback event that will then run your code, but you will need to remove any reference on the server side code to the document and the elements of it.

  • #7
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok I am not too good in server side Javascript

    As i understand 1. u need to run asp script when usew click ?
    then add hidden fields as said above
    or store what u want in cookies

    and 2. if u want to pass something on javascript from asp then

    in braket helpdesk ('<%=urValue%>')

    .

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    As BaldEagle mentioned, the two functions (helpdesk and updates) should be on the client side of the page. dont see the whole page but you have to move the "%>" sign to the line just below the line which says: UpdateRecord.Open(SQLQuery, DBConn);

    That way your functions are not anymore at the serverside part of the page. now you have to put a <script> tag before and a </script> tag after the functions (but they might be on the page already) then things should be better....
    I am the luckiest man in the world

  • #9
    New Coder
    Join Date
    Sep 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you to everyone who pitched in.

    I ended up making server-side scripting to post all of the data I needed to SPAN and TABLE elements that were set STYLE="display: none". When a user clicks the apropriate button, the client-side scripting changes the "display" equal to null and the data appears.

    While this method is crude, and created another 20 lines of code, it works.

    Thanks to Miranda and BaldEagle for reminding me that ASP is server-side, and parsed before the page is ever displayed. That was the simple, painfully obvious thing I was overlooking.

    Sorry to bother everyone with such a "newbie" issue.

  • #10
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank ya'll. This post was very helpful for a newbie like me.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •