Web Analytics Made Easy -
StatCounter Identifying Table Column, 2D arrays - CodingForum

Announcement

Collapse
No announcement yet.

Identifying Table Column, 2D arrays

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Identifying Table Column, 2D arrays

    Hi,


    I want to create a table time (horizontal e.g. 0900 , 0930) by date (vertical e.g. 1, 2, 3, 4...). There will be checkbox within the table box. When the user click on the checkbox and press the submit button the columns in the table that the checkbox reside will change color - How do I tell the system to change the color of the particular column in the table?

    Also, I want the 2 data identified by the checkbox, date and time to be stored in the database. How do I do it? Again, how I tell the system the column that the checkbox resides represent e.g. 0900, 1/1/2004?

    I need to do all this in ASP Javascript, can someone help me?

  • #2
    Okay now it would be easier to see your code.

    How are yo writing out these check boxes? Are they hard coded or are they dynamic (Please say Dynamic).

    What are you columns that are have in your database that you want to store this information with?

    We need to know these things to help you out. Otherwise it is like a blind man and a blind guide dog, not going to work too well.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

    Comment


    • #3
      Hi,

      This ia roughly what I want to do, but I only create 3 rows and 2 column to test.. Would it be easier to do it using array?

      <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
      <!--#include file="Connections/conn_RoomReservation.asp" -->
      <%
      // *** Edit Operations: declare variables

      // set the form action variable
      var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
      if (Request.QueryString) {
      MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
      }

      // boolean to abort record edit
      var MM_abortEdit = false;

      // query string to execute
      var MM_editQuery = "";
      %>
      <%
      // *** Insert Record: set variables

      if (String(Request("MM_insert")) == "form1") {

      var MM_editConnection = MM_conn_RoomReservation_STRING;
      var MM_editTable = "dbo.Test";
      var MM_editRedirectUrl = "";
      var MM_fieldsStr = "checkbox|value|checkbox2|value|hiddenField|value";
      var MM_columnsStr = "NearPanty0900|none,'Y','N'|NearPantry0930|none,'Y','N'|Date|none,none,NULL";

      // create the MM_fields and MM_columns arrays
      var MM_fields = MM_fieldsStr.split("|");
      var MM_columns = MM_columnsStr.split("|");

      // set the form values
      for (var i=0; i+1 < MM_fields.length; i+=2) {
      MM_fields[i+1] = String(Request.Form(MM_fields[i]));
      }

      // append the query string to the redirect URL
      if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
      MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + Request.QueryString;
      }
      }
      %>
      <%
      // *** Insert Record: construct a sql insert statement and execute it

      if (String(Request("MM_insert")) != "undefined") {

      // create the sql insert statement
      var MM_tableValues = "", MM_dbValues = "";
      for (var i=0; i+1 < MM_fields.length; i+=2) {
      var formVal = MM_fields[i+1];
      var MM_typesArray = MM_columns[i+1].split(",");
      var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
      var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
      var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
      if (formVal == "" || formVal == "undefined") {
      formVal = emptyVal;
      } else {
      if (altVal != "") {
      formVal = altVal;
      } else if (delim == "'") { // escape quotes
      formVal = "'" + formVal.replace(/'/g,"''") + "'";
      } else {
      formVal = delim + formVal + delim;
      }
      }
      MM_tableValues += ((i != 0) ? "," : "") + MM_columns[i];
      MM_dbValues += ((i != 0) ? "," : "") + formVal;
      }
      MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ") values (" + MM_dbValues + ")";

      if (!MM_abortEdit) {
      // execute the insert
      var MM_editCmd = Server.CreateObject('ADODB.Command');
      MM_editCmd.ActiveConnection = MM_editConnection;
      MM_editCmd.CommandText = MM_editQuery;
      MM_editCmd.Execute();
      MM_editCmd.ActiveConnection.Close();

      if (MM_editRedirectUrl) {
      Response.Redirect(MM_editRedirectUrl);
      }
      }

      }
      %>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <title>Untitled Document</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </head>

      <body>
      <form name="form1" method="POST" action="<%=MM_editAction%>">
      <table width="200" border="1" cellspacing="0" cellpadding="0">
      <tr>
      <td>&nbsp;</td>
      <td>NearPantry </td>
      </tr>
      <tr>
      <td>0900</td>
      <td><input type="checkbox" name="checkbox" value="Pantry0900"></td>
      </tr>
      <tr>
      <td>0930</td>
      <td><input type="checkbox" name="checkbox2" value="Pantry0930"></td>
      </tr>
      </table>
      <p>
      <input type="submit" name="Submit" value="Submit">
      <input name="hiddenField" type="hidden" value="230204 ">
      </p>

      <input type="hidden" name="MM_insert" value="form1">
      </form>
      <p>&nbsp;</p>
      </body>
      </html>
      Last edited by Jesviko; Feb 23, 2004, 04:06 AM.

      Comment

      Working...
      X