• ASP question

    Author
    Topic
    #379028

    I hoping to somehow create a FAQ section for my website. At the moment, I’m displaying the question and then the answer, and so on and so on. So for example, my output looks like this…
    Q ….
    A …
    Q…
    A…

    What I’m hoping to do is somehow group the questions and link to them within the document using anchor tags to the correct corresponding answer. So I need to group the answers down below as well. Any clue how I can accomplish this. Here is my code up to this point. At the moment, I’m not pulling the ID from the db, but each question/answer has a uniqued ID….

    FAQ (Frequently Asked Questions)

    If your can’t find an answer, please submit your question through the “Ask a Question” section below.

    <%

    Thanks beforehand!!!!

    Viewing 0 reply threads
    Author
    Replies
    • #629582

      Hi Muscle (I used to be mostly muscle, but not anymore… smile)

      You’re definitely on the right track. WIth just a few tweaks, you’ll be in business.

      To add an anchor to the corresponding answer, I would suggest using each answer’s ID, as you mentioned.

      Simply use the following ASP for your answer item (note that you can also refer to a field’s value with Recordset1(“Fieldname”) – it’s just easier to type that way)

      <a name="”>

      Also, be sure to add the correct field to your Recordset.Source line (I used “AnswerID”, but replace that with your ID field’s name).

      Do you also have a section of the page that has the Questions with links to the corresponding answer?
      If so, you could set it up like this:

      <% Do Until Recordset1.EOF
      Response.Write("” & Recordset1(“Question”) & ““)
      Recordset1.MoveNext
      Loop
      %>

      Hope this helps – please post back if you have any more questions (or answers laugh)

      • #629586

        Thanks so much for the prompt response Mark. I’m new to ASP(ColdFusion Junkie) so try to bear with me doh . I have the following table structure(fields) in my Access DB…
        ID, Answer, Question, and FAQ. ID is the generated number, Answer and Question are of course self explanatory, and FAQ is if it is included in the FAQ section. What I’m hoping to accomplish is…

        I’m hoping to display all my questions first and hopefully numbered like 1. 2. 3. etc. If you know how to do that, It would be greatly appreciated. I can display them, just cant get a number to display next to them. Second I want to have each as a link to the specific answer which will be further down the page in a group of answers. At the moment, I’m displaying the question and then the answer right after it. But I think this model would be much better. Either way, thanks again soo much for helping.

        Code right now…

        • #629589

          OK – that helps me have a better idea of your needs… I would suggest adding another field in your table for Question number (since the Auto generated ID field may possibly skip numbers). Then number these sequentially as needed – If you use the HTML tag (ordered list), the question and answer numbers may possibly change from time to time. It will give you more control over the numbers if you create them yourself. (I added “ORDER BY faqNumber” to your SQL so it would sort by the new faqNumber field.)

          This may be a bit of a long post with the code, but bear with me. I’ll comment in the code as needed. Also, I’ll use more of the Response.Write method because it’s a little more efficient than bouncing in and out of script () tags.

          (Note that I used
          to separate the questions and answers. You may choose to use a table as you did in the code you posted. Simply change the tags and you’ll be fine – be careful of the script syntax, though.)

          'Your connection code (with the addition of a new field - faqNumber
          Set Recordset1 = Server.CreateObject("ADODB.Recordset")
          Recordset1.ActiveConnection = MM_connectDB_STRING
          Recordset1.Source = "SELECT ID, faqDate, faqNumber, Question, Answer " _
            & "FROM tbl_FAQ where FAQ = 1 ORDER BY faqNumber"
          Recordset1.CursorType = 0
          Recordset1.CursorLocation = 2
          Recordset1.LockType = 1
          Recordset1.Open()
          Recordset1_numRows = 0
          Repeat1__numRows = -1
          Repeat1__index = 0
          Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
          
          'Write the Question list with links to the Answer Anchors and the new faqNumber field as numbers
          Response.Write("FAQ - Questions:")
            Recordset1.MoveFirst
            Do Until Recordset1.EOF
                Response.Write("" & Recordset1("faqNumber") & ".
          • #629590

            You’re going to kill me. I’ve been told I can’t touch the database. So it’s not a problem to leave out the ordering. So basically I’m just going to display the group of questions and then the group of answers below it. Of course with anchor tags, which you have generously already provided. I’ve set up your initial code w/o the questions becuase I get an error. It’s like I need to do somekind of different loop. Here is what I have which is almost complete… Thanks again for everything. It;s people like you that make learning so enjoyable. Thanks Again!!!

            <a name="”>

            • #629741

              Sorry for the delay – I was out at meetings all afternoon…

              Ok – no need to worry about the database. Why don’t you use the

                (Ordered List) tag. That will give the user a way to see a number. Since there’s an answer for every question, the numbering will match without any problem. Whether or not you use a table is up to you – you don’t really need one if you use the OL tag…

                I’m not sure why the code I posted crashed – it’s hard to tell without seeing your entire page and database setup.

                I’ll try again. Questions:

                [*]

              ….

              Answers:

                [*]<a name="faq”>

              Give that a shot… If you get an error, please post it with the line that’s causing the problem.

              Keep us posted!

            • #629859

              Mark:

              Can’t thank you enough. The last code you so generously posted worked beautifully!! Again, thanks for everything, and if you ever have a question about ColdFusion, please let me know.

              Thanks Again!!!

            • #629869

              I’m glad to hear that it worked! I imagine it’s a big change to move from ColdFusion to ASP… but it seems like you’re on the right track.

              Have you worked with ColdFusion MX? I have the “Personal” edition that comes with StudioMX, but I haven’t taken the time to play with it – mainly because all of the web hosts I work with only have CF 5.

              I’m anxious to have the opportunity to consume Web Services with CF MX. I’ve played with it a bit on my copy and it’s REALLY powerful. I haven’t tried doing the same with ASP.NEtT, so I’ll be curious to see how easy it is there.

              Have a great day!

            • #630839

              Hey MarkJ:

              To answer your question, I was a big ColdFusion 4.5 fan and have just now started working with MX. Unfortunately, I have not used it enough to form an opinion, but will elt you know when I do.

              I was hoping to ask you a question if you had some time? Do you know of a script that tests to see if the Flash Player and if Windows Media Player is installed. I need to test in my ASP page to see if they’re installed, and if so provide the relative links. So for example, if Flashis installed, display the flash file, and if WMP is installed, display the WMP file, and if both are installed, display both files. I hope I’m clear enough. I figured you would be the pro to ask. Thanks again!!!

            • #630841

              Hi Muscle,

              FlashMX will automatically generate the HTML/JavaScript to detect for the selected version when you publish your SWF file (File | Publish).

              If you don’t have access to this software, you can check a couple of my websites for a good example (both are located on the opening page). Both of these check for version 5 of Flash Player (my choice), and show alternate content if it’s not present (in this case, a JPG):
              http://JTimms.com[/url%5D
              http://MeridianSongProject.org[/url%5D

              (Based on your previous posts, I’ll assume that you are comfortable digging through HTML and JavaScript to find the necessary info you need. If, however, you need more specific help please let me know.)

              As for detecting WMP, I’ve never tried it, but I imagine the JavaScript is very similar to the Flash detection process. The only difference is that you’re checking for WMP instead of Flash. I’ll bet Microsoft has some code samples on their website that will demonstrate this. I’ll see if I can locate anything like that.

              In the meantime, I hope this helps! thumbup

            • #630878

              Thanks so much for the prompt reply Mark. By the way, you can call me Nick:o) (FYI, I love to spend all of my free time in the gym, so that’s where muscle comes from). Anyway, I’ve been able to write a script that checks for both the Windows Media Player and Flash Player. Here is my problem now. I have an ASP page in which I’m displaying media files that deal with that specific text (page). I’ve created an additional function in my global.asp page like so…

              var agt=navigator.userAgent.toLowerCase();
              var ie = (agt.indexOf(“msie”) != -1);
              var ns = (navigator.appName.indexOf(“Netscape”) != -1);
              var win = ((agt.indexOf(“win”)!=-1) || (agt.indexOf(“32bit”)!=-1));
              var mac = (agt.indexOf(“mac”)!=-1);

              if (ie && win) { pluginlist = detectIE(“ShockwaveFlash.ShockwaveFlash.1″,”Shockwave Flash”) + detectIE(“MediaPlayer.MediaPlayer.1″,”Windows Media Player”); }
              if (ns || !win) {
              nse = “”; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes.type.toLowerCase();
              pluginlist = detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("application/x-mplayer2","Windows Media Player");
              }

              function detectIE(ClassID,name) { result = false; document.write('n on error resume next n result = IsObject(CreateObject(“‘ + ClassID + ‘”))n’); if (result) return name+’,’; else return ”; }
              function detectNS(ClassID,name) { n = “”; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+”,”; return n; }

              pluginlist += navigator.javaEnabled() ? “Java,” : “”;
              if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);

              What I’m hoping to do now is somehow call this function in my page, and write some kind of ASP code to check for each player and if detected display the link or image.

              So for example, if a user has WMP but no flash, I’d like to only display the Windows Media Player link/image. Is this possible? Again, thanks so much for everything.

            • #630900

              Hi Nick,

              You mentioned including this function in your “global.asp” page – do you mean “global.asa”?

              I’m not clear on what’s not working… It could be that the Lounge is improperly displaying all of your code – try placing it inside the [ pre ] … [ / pre ] tags… That allows you to post properly formatted code without the lounge mistaking a [ i ] for italics.

              I’m not sure how you’re referencing this function. I would suggest a similar approach, except with an Include directive and a JavaScript function name instead of Server-side function name:


              (detect.inc below)

              function detect() {
              //Insert your code here
              }

              Then call your function to detect totally on the client side. Was the ASP stuff part of THIS process, or was it for other things on the page?

              Hope this helps…

            • #630905

              OK, I think I’m all messed up:o) Let me try to do a better job of explaining because I have myself confused, lol. I’ve got a page called contents.asp which is called into the main page to display the pertinent information like so…

              contents.asp
              [ pre ]

              <A href="java script:openWindow('m/01/001.asp’, ‘media’, ‘width=600,height=400,scrollbars=no’)”>
              (Windows Media Sample)

              <A href="java script:openWindow('m/01/111.asp’, ‘media’, ‘width=550,height=338,scrollbars=no’)”>
              (Flash Sample)

              <A href="java script:openWindow('m/01/201.asp’, ‘media’, ‘width=600,height=400,scrollbars=no’)”>
              (HTML Sample)

              [ / pre ]

              I thought what a luxury it would be to the user if I could only display the specific links for the players they have installed and leave the others transparent. So if the user has no Flash, he/she wouldn’t be able to view the Flash link. Now the HTML link would always be displayed. I have a javascript which detects whether or not the players are displayed, I’m just not sure how to implement it in my code. I apologize about the global.asa file. I was totally wrong. I need to somehow include this into the contents.asp file. Here is the javascript code that is working beautifully…

              [ pre ]

              <!–
              var agt=navigator.userAgent.toLowerCase();
              var ie = (agt.indexOf("msie") != -1);
              var ns = (navigator.appName.indexOf("Netscape") != -1);
              var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
              var mac = (agt.indexOf("mac")!=-1);

              if (ie && win) { pluginlist = detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player"); }
              if (ns || !win) {
              nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes.type.toLowerCase();
              pluginlist = detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("application/x-mplayer2","Windows Media Player");
              }

              function detectIE(ClassID,name) { result = false; document.write('n on error resume next n result = IsObject(CreateObject(“‘ + ClassID + ‘”))n’); if (result) return name+’,’; else return ”; }
              function detectNS(ClassID,name) { n = “”; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+”,”; return n; }

              pluginlist += navigator.javaEnabled() ? “Java,” : “”;
              if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);

              [ / pre ]

            • #630910

              Hi Nick,

              I should have explained – I intentionally left spaces in the [ pre ] tags so they wouldn’t be picked up. Try again without the spaces… I included a lot of HTML code and forgot the pre tags – anything that was a comment () was left out of the post… Needless to say, I learned the hard way. stupidme

              Even without the help of the formatting, I think I understand the problem. Detecting the plugins happens totally on the Client side. Therefore, you’ll need JavaScript to detect whether they have the appropriate plugins and decide whether or not to show the links – assuming this all happens on ONE page. Alternatively, you could detect the plugins on one page, send a form variable back to the server, then determine which links to show on following pages. Does that make sense?

              The logic for scenario 1 would be: (all JavaScript)
              1) Detect Plugin
              2) If Plugin = True, show link
              3) else (Plugin = False), don’t show link

              The logic for scenario 2 would be: (JavaScript + ASP)
              1) Page 1 – Detect Plugin, set Form variable to Plugin Status (perhaps true/false)
              2) Page 2 – If Request.Form(PluginStatus) = True, Generate link
              3)… Else (Request.Form(PluginStatus) = False), don’t generate link

              I hope that helps… If not, post back. We’ll keep it rolling until you get it right! smile

            • #631131

              Hi Mark:

              Would it be possible to detect it on my main index.asp page and then set a session variable? Of course I have no clue how to do this, but it sounds good cool

            • #631140
            • #631149

              Hey Mark:

              I decided to slow down and just test my script in an asp page. (It works fine as an .htm page) Well I’m getting the following errors. Any clue?

              Error Type:
              Active Server Pages, ASP 0138 (0x80004005)
              A script block cannot be placed inside another script block.
              /testing/detect.asp, line 20

              I attached the code in a text file to keep formatting:o)

            • #631153

              It looks like you’re nesting two client-side scripts.

              There’s a VBScript block (client-side) inside a JavaScript block. AFAIK, you can’t do that.

              However, you CAN nest a Server-side block inside a client-side block. For example, if I wanted to include a Session variable in my JavaScript function I could do this:

              function movenext() {
                  document.frmNext.action = '';
                  document.frmNext.submit();
              }
              

              This will work fine, even though most code editors will not recognize the block inside the JavaScript. The ASP blcok processes on the server and returns a value to the client. The client only reads the value – not the script block.
              You can not, however, nest client-side scripts (…………..). That’s where your error was coming from.

              Hope this helps

            • #631163

              Yes, that helped tremendously. I’ve decided to just do the processing on the main page and change the extension from .asp to .htm (index.htm). So when the user comes to the site, it automatically learns the users plugins. I guess I need to set a “Form variable to Plugin Status (perhaps true/false)”, as you stated. Is there any way to make this transparent. Did I say I sure wish this was ColdFusion. Perhaps pass it in a URL, if that can even be done.

            • #631168

              It sounds like you’re getting closer. This is the point that I’ll ask how your page flow works… Obviously, the user starts at Index.htm/asp. What options does the user have after this?
              Does the user have the option to click a number of links after this, or do they have to follow a set path in order to get to the media?

              If it’s the second option, you can leave your index page as .HTM and simply pass a hidden form variable to the next page in the line (which will be an ASP page) to process Server-side. In other words, you will use the detection routine you currently have, generate a variable (let’s call it varResult), then add that variable to a form (called form1 for now). Then, instead of using a standard link to move to the next page, simply submit the form (with the next page as the action of the form). Here’s the gist of what’s happening on the first page:

              
              
              
              
              //Detect plugin code - varResult is the result
              //----tag this onto the end of the block
              //This will set the hidden variable in "form1" to the result
              document.form1.varResult.value = varResult;
              //properly close the block with the appropriate }}}'s
              
              
              Next Page (whatever you want to call it)
              
              ---------------
              Next Page (asp)
              ---------------
              
              <% 
              'Set session variable (varResult) to the result coming from the form
              Session("varResult") = Request.Form("varResult")
              
              'Use server-side logic to show or hide links based on this result
              If Session("varResult") = True Then
                  Response.Write("Windows Media Version")
              Else
                  Response.Write("Flash Version")
              End If

              Does that make sense? How to use the variable is up to you. You can pass true/false, or better yet, you might want to pass a number – 1 for Flash, 2 for WMP, 3 for both, 0 for neither?


              The first option mentioned (i.e. the user can click a NUMBER of links) might be better served by using a Querystring to pass two things: the varResult variable and the next page’s name. You could populate each of the links in the main page with the name of an ASP page that stores the varResult as a session variable and simply redirects the user to the next page they have chosen. Your links in the first page would all look like this:
              Video 1
              (Again, use whatever you want for varResult – true/false, numbers, text, whatever. Also, remember that you’ll need to use proper JavaScript syntax to generate the variable and include it in the querystring of each link.)

              Then, have an ASP page (“process.asp”) that adds the result as a session variable, then redirects the browser to the requested next page:

              That’s it…. The session variable will be set and you can use each respective destination page to determine which links to show on Server side based on the variable.

              Whew – thats a lot to think about… Keep us posted with your progress!
              I hope my comments are more help than confusion…

            • #631174

              Mark, I about jumped out of my skin with joy when I put your code to use. I have hopefully only one last question. I love the idea of passing a number in the variable like you quoted “1 for Flash, 2 for WMP, 3 for both, 0 for neither”. My only question is how? This I believe would solve everything. Again I’ve attached my code in a text file so you can see. Again thank you soo much for everything. I can’t possibly thank you enough!!!

            • #631178

              I’m glad to hear that it’s getting close….

              (by the way, the text file attachment didn’t make it – perhaps you can edit and re-attempt the attachment)

              As for the variable, do you mean you’re not sure how to generate it? There are quite a few ways, including client AND server side. I guess the easiest thing would be to do it in JavaScript along with your initial detect routine… Assuming you have 2 variables – 1 for WMP (true/false) and 1 for Flash (true/false).

              You can use a series of IF statements (although I’m sure there’s probably a better way):

              if (varWMP == true && varFlash == true) {
                varResult = 3; //both
              }
              else if (varWMP == false && varFlash == true) {
                varResult = 1; //only Flash
              }
              else if (varWMP == true && varFlash == false) {
                varResult = 2; //only WMP
              }
              else if (varWMP == fasle && varFlash == false) {
                varResult = 0; //neither
              }

              Then you can just pass your varResult along through the form…

              Is this project something that we can see on the Internet? If so, I’d love to see the result when it’s ready…

              Keep us posted (no pun intended)

            • #631182

              Let me try the attachment again. It helps to remember:o) I believe I may have messed up setting my variables in my javascript.

            • #631187

              If that doesn’t work, you may want to try writing the hidden variable with the java script:
              document.write(”);

              Give that a shot… I’m sure there are other ways to make it happen as well.

            • #631420

              Good Morning Mark:

              Everything is working perfectly!! As soon as I get it up I will be sure to provide you with a link. Thanks again!! I wanted to ask you what I think will be an easy question to answer I hope:o) I’m trying to put in an if statement which states if either one of my sessions, “Session(“hasFlash”) and Session(“hasWMP”)” exists, then ignore this snippet of code. Any clue on how I set that up.

            • #631431

              Hi Nick,

              Ahh – your request is a very easy one (especially when compared to the challanges you’ve faced to get this far)…

              Simply set up an If…then structure with an ASP block on the server-side to generate or not generate the desired code:

              Flash Link

              WMP Link

              (Alternatively you can keep the whole thing inside a script block like this):

              You might need to use a similar structure to the Javascript you used before – where there were 4 alternatives – Flash, WMP, Both, Neither…
              You can just modify your IF statment to include all choices:

              If Session(“hasFlash”) AND Session(“hasWMP”) Then

              Elseif Session(“hasFlash”) AND NOT Session(“hasWMP”) Then

              Elseif NOT Session(“hasFlash”) AND Session(“hasWMP”) Then

              Else
              ..
              End If

              Hope this helps! smile

            • #631448

              Mark:
              You beat me to the punch. I was going to write that I solved my solution with the following…

              0 OR len(Session(“hasWMP”)) > 0 Then %>

              But I do appreciate you taking the tim ethis morning to get back to me so quickly. Again I truly appreciate all of your help!! Thanks again.

    Viewing 0 reply threads
    Reply To: ASP question

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: