Loading ...
Sorry, an error occurred while loading the content.

11918Re: Process Database in javaScript

Expand Messages
  • Jon Stephens
    Oct 1, 2005

      You're mixing up clientside and serverside. I don't think you really understand
      the difference.

      Your ASP code sends content to the client. The client processes this. The client
      does not "see" the ASP code itself. The server does not "see" the clientside JS
      code as code, merely as content (text) to be sent to the client.

      You've also had several responses to this same question already, but apparently
      you've not tried to make use of any of them. This sort of behaviour is really
      good for pissing people off. Just So You Know.

      It *is* possible to generate clientside code with serverside code - I've done it
      using ASP and PHP. But it's not simple, and you must VERY clear on what's
      happening where, and in what order.

      > Date: Fri, 30 Sep 2005 10:00:57 -0700 (PDT)
      > From: Kirpa Mehta <kirpa226@...>
      > Subject: Process Database in javaScript
      > Please explain how to process a list of databse items from within JavaScript. If their is any other way. I try it but i think the way i use is wrong.
      > Thanks,
      > <HTML>
      > <script>

      No no no no no. There should be no other HTML tags inside a script block!

      > <head>
      > function f1() {

      Please name your functions with something descriptive. "f1" tells us nothing
      about what this script is supposed to do.

      > document.write("<head>");
      > document.write("<TITLE>Test Form</TITLE>");

      You don't need these two lines. Your page already has a starting <head> tag, the
      <form> needs to go inside the <body>, and you can't put a <title> inside the <body>.

      > document.write("<form name='f1' method='post'>");
      > document.write("Student:<select name='stud1'>");
      > document.write("<option value="" selected>Select</option>");
      > <% Do while not rs1.EOF %>

      ^ There's no recordset to loop through yet, because you've not yet sent the
      query and created it. You need to move that piece of code here.

      > <option value='<%=rs1("studno")%>'><%=rs1("studname")%></option>

      ^ You need to generate the text of a document.write() call (as a quoted string),
      because this is inside the text of the clientside JS function.

      > <% rs1.movenext
      > loop
      > %>
      > document.write("</SELECT>");
      > document.wrie("</form></head>");
      > }
      > </script>
      > </head>
      > <body>
      > <%
      > newdate=Date
      > Set rs1 = con.Execute("select * from student")

      ^ You need to do this *before* you can pull any records from the DB. SO this
      needs to be moved to some point before the beginning of the ASP Do While loop.

      > %>

      Then you need to call your clientside JS function here.

      > </body>
      > </html>

      In other words, your page needs to look something like this:

      <script type="text/javascript">
      function writeForm() // Begin JS function
      document.write("<form name='f1' method='post'>");
      document.write("Student:<select name='stud1'>");
      document.write("<option value="" selected>Select</option>");
      'Generate a set of JavaScript document.write() calls
      'inside the body of the JS function

      Set rs1 = con.Execute("select * from student")

      Do While Not rs1.EOF
      Response.write "document.write("" <option value=" & Chr(39) &
      "<%=rs1("studno")%>" & Chr(39) & "><%=rs1("studname")%></option>"")" & VbCrLf
      <script type="text/javascript">

      // Now call the clentside JS function that
      // writes out the form HTML:



      It's been a while since I did any VB or ASP coding - and since I don't have a
      Windows server handy, I can't actually test this - but it should be close to
      what you need.

      This message has not been scanned for viruses.

      Since I do not use a Microsoft operating
      system or software, and use only plaintext
      for email, there is little need to do so.
    • Show all 9 messages in this topic