0

I am working on a Classic ASP project where I am updating multiple records in a table with single Submit button. Each row has select box and text box and user can update all the rows. While sending parameters to stored procedure , I want to pass only those values where input values ( select box or text box ) have been changed. I can't figure how should I do that. sCycleTime(Id) and sComment(id) contains values of Select Box and Textbox of all the rows. sProfile(id) and sProcess_Step_Sequence(Id) are two id's binded in each Select box and Textbox. Eg: DrpDwn_1_4 and Txtbox_1_4 and so on... Template link : https://drive.google.com/drive/folders/1MrBxo89vvedMbt1pSYzvbLUFhGfU6ocL?usp=sharing

Edit: I am not looking for a way to pass paramter to stored procedure. See my requirement was to update multiple records at once , by clicking Submit button. So on Submit click I have javascript function which is being used to set form's Value, action , method and then Submit. In ASP I have 'for each' loop which is getting Values of all Text boxes and Select boxes. then appending those values to string separated by special characters and finally reading them in the database. Everything is working fine but I want to send only those rows to update where values in the text and select box has changed –

Html source :

<html>


<head>
<title> Dashboard:</title>
<script language="JavaScript">
 var gAutoPrint = true; // Tells whether to automatically call the print function
 function printSpecial()
  {
   if (document.getElementById != null)
    {
    var html = '<HTML>\n<HEAD>\n';
    if (document.getElementsByTagName != null)
     {
     var headTags = document.getElementsByTagName("head");
     if (headTags.length > 0)
      html += headTags[0].innerHTML;
     }

     html += '\n</HE>\n<BODY>\n';

    var printReadyElem = document.getElementById("printReady");

    if (printReadyElem != null)
     {
      html += printReadyElem.innerHTML;
     }
    else
     {
      alert("Could not find the printReady function");
      return;
     }
    html += '\n</BO>\n</HT>';

    var printWin = window.open("","printSpecial");
    printWin.document.open();
    printWin.document.write(html);
    printWin.document.close();
    if (gAutoPrint)
     printWin.print();
    }
   else
    {
     alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
    }
  }
  
  function validate()
  {
      //alert('here');
      var elements = document.getElementById("frmDtls").elements ;
      var val = [] ;
      var flag = true;
      var x = -1;
      var y = 0;
        
      if(flag == true)
      {
          document.frmDtls.hfrom.value = 'Updt' ;
          document.frmDtls.method = "post" ;
        document.frmDtls.action = "samepage.asp" ;
          document.frmDtls.submit();
         // alert("Record has been Updated Successfully!");
           //window.location.href = window.location.href;
         // location.reload();
       
                             
      }
//      alert(flag);
  }  
</script>

</head>

<body background="Images/Notebook.jpg">


<div align="center">
  <center>


<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
  <tr>
    <td width="100%" align="center">
    <img border="0" src="Axalta Coating Systems Logo.jpg" width="1200" height="60"></td>
  </tr>
</table>





<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
  <tr>
    <td width="100%" bgcolor="#C0C0C0" align="center"><b>
    <font face="Times New Roman" size="4"> CYCLE TIMES and UNITS for UPDATING </font></b>&nbsp;
     </TD>
  </tr>
</table>
<div id="printReady">
<div align="center" id="formdiv"><center>
<form id="frmDtls" name="frmDtls">
<!--<form id="frmDtls" name="frmDtls" target="MyFrame">-->
<iframe id="MyFrame" name="MyFrame" style="display:none;"></iframe>
<input type="hidden" name="hfrom" value = "">

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
  <tr>
    <td width="70%" bgcolor="#C0C0C0" align="center"><b>
  <font face="Times New Roman" size="5">SELECTED DUAL CODE DETAILS  </font></b>&nbsp;</td>
 <td width="13%" align="Middle" valign = "Middle" bgcolor="#FFFF00">
  <input type="button" name='update' value = 'Update' onclick='validate();'>
 </TD>
 <td width="17%" bgcolor="#C0C0C0" align="Center">
  <b><font face="Times New Roman" size="2"> 
    LATEST POSTING DATE / TIME 2/13/2019 7:09:20 AM</font></b>&nbsp;     
 </TD> 
  </tr>
</table>


<table BORDER="1" CELLSPACING="1" CELLPADDING="1"
style="font-weight: normal; letter-spacing: normal; text-align: left; width:100%;">
  <tr align="center">
    <th><small><small><span style="color:darkgreen;font-weight:bold">Profile ID</small></small></th>
    <th><WIDTH="200"><small><small><span style="color:green;font-weight:bold">DUAL CODE</small></small></th> 
 <th><small><span style="color:darkgreen;font-weight:bold">Description</small></th>
 <th><small><span style="color:darkgreen;font-weight:bold">R/D Material?</small></th>
 <th><small><small><span style="color:darkgreen;font-weight:bold">Process Step Name</small></small></th>
 <th><small><small><span style="color:darkgreen;font-weight:bold">Process Step Sequence</small></small></th>
 <th><small><small><span style="color:darkgreen;font-weight:bold">FROM Event Status</small></small></th>
 <th><small><small><span style="color:darkgreen;font-weight:bold">TO Event Status</small></small></th>
 <th><small><small><span style="color:darkblue;font-weight:bold">Current CYCLE TIME</small></small></th>
 <th><small><small><span style="color:darkred;font-weight:bold">Updated CYCLE TIME</small></small></th> 
 <th><small><small><span style="color:darkblue;font-weight:bold">Cycle Time Units</small></small></th>

 <th><small><small><span style="color:darkred;font-weight:bold">Updated Units</small></small></th>

 <th><small><small><span style="color:darkblue;font-weight:bold">Comments</small></small></th>
   </tr>
   <tr>
   <td><input type="Hidden" name="l_enteredpartialdualcode"   value=""  > </td>
 <td><input type="Hidden" name="l_selecteddualcodes"   value="1026-FD195, 1143-01427"  > </td>
 <td><input type="Hidden" name="l_selectedprocessstepnames"   value=""  > </td>
 <td><input type="Hidden" name="l_selectedgbtindicato"   value="Both"  > </td>
 <td><input type="Hidden" name="l_multipledualcodess"   value=""  > </td>
  </tr> 
<TR align=center><TD Width=90 Height=3 nowrap ><B>1</B></TD><TD Width=90 Height=3 nowrap ><B>1026-FD195</B></TD><TD WIDTH=200 Height=3><small><small><B>1026-FD195 E500546 DARK GRAY WBPR</B></small></small></TD><TD WIDTH=30 Height=3><small><small><B></B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>Load_Cycle</B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>2</B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>LDGS      </B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>LDGC      </B></small></small></TD><TD WIDTH=70 Height=3><B>6</B></TD><TD WIDTH=70 Height=3><small><small><B><Select name = 'DDSQ_1_2' font-size=1><option value = '1' >1</option><option value = '2' >2</option><option value = '3' >3</option><option value = '4' >4</option><option value = '5' >5</option><option value = '6' selected>6</option><option value = '7' >7</option><option value = '8' >8</option><option value = '9' >9</option><option value = '10' >10</option><option value = '11' >11</option><option value = '12' >12</option><option value = '13' >13</option><option value = '14' >14</option><option value = '15' >15</option><option value = '16' >16</option><option value = '17' >17</option><option value = '18' >18</option><option value = '19' >19</option><option value = '20' >20</option><option value = '21' >21</option><option value = '22' >22</option><option value = '23' >23</option><option value = '24' >24</option><option value = '-1' >Clear</option></Select></B></small></small></TD>
  <TD WIDTH=70 Height=3 nowrap><small><small><B>
Hours     </B></small></small></TD><TD WIDTH=70 Height=3><small><small><B></B></small></small></TD>
            <td WIDTH=100 Height=3><small><small><B><input type="text" name="txt_1_2" value="test1" >
   </B></small></small></TD>
   
<TR align=center><TD Width=90 Height=3 nowrap ><B>1</B></TD><TD Width=90 Height=3 nowrap ><B>1026-FD195</B></TD><TD WIDTH=200 Height=3><small><small><B>1026-FD195 E500546 DARK GRAY WBPR</B></small></small></TD><TD WIDTH=30 Height=3><small><small><B></B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>Test_Cycle</B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>4</B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>TSTS      </B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>TSTC      </B></small></small></TD><TD WIDTH=70 Height=3><B>6</B></TD><TD WIDTH=70 Height=3><small><small><B><Select name = 'DDSQ_1_4' font-size=1><option value = '1' >1</option><option value = '2' >2</option><option value = '3' >3</option><option value = '4' >4</option><option value = '5' >5</option><option value = '6' selected>6</option><option value = '7' >7</option><option value = '8' >8</option><option value = '9' >9</option><option value = '10' >10</option><option value = '11' >11</option><option value = '12' >12</option><option value = '13' >13</option><option value = '14' >14</option><option value = '15' >15</option><option value = '16' >16</option><option value = '17' >17</option><option value = '18' >18</option><option value = '19' >19</option><option value = '20' >20</option><option value = '21' >21</option><option value = '22' >22</option><option value = '23' >23</option><option value = '24' >24</option><option value = '-1' >Clear</option></Select></B></small></small></TD>
  <TD WIDTH=70 Height=3 nowrap><small><small><B>
Hours     </B></small></small></TD><TD WIDTH=70 Height=3><small><small><B></B></small></small></TD>
            <td WIDTH=100 Height=3><small><small><B><input type="text" name="txt_1_4" value="" >
   </B></small></small></TD>
   
<TR align=center><TD Width=90 Height=3 nowrap ><B>1</B></TD><TD Width=90 Height=3 nowrap ><B>1026-FD195</B></TD><TD WIDTH=200 Height=3><small><small><B>1026-FD195 E500546 DARK GRAY WBPR</B></small></small></TD><TD WIDTH=30 Height=3><small><small><B></B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>FILL_Cycle</B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>6</B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>FLGS      </B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>FLGC      </B></small></small></TD><TD WIDTH=70 Height=3><B>4</B></TD><TD WIDTH=70 Height=3><small><small><B><Select name = 'DDSQ_1_6' font-size=1><option value = '1' >1</option><option value = '2' >2</option><option value = '3' >3</option><option value = '4' selected>4</option><option value = '5' >5</option><option value = '6' >6</option><option value = '7' >7</option><option value = '8' >8</option><option value = '9' >9</option><option value = '10' >10</option><option value = '11' >11</option><option value = '12' >12</option><option value = '13' >13</option><option value = '14' >14</option><option value = '15' >15</option><option value = '16' >16</option><option value = '17' >17</option><option value = '18' >18</option><option value = '19' >19</option><option value = '20' >20</option><option value = '21' >21</option><option value = '22' >22</option><option value = '23' >23</option><option value = '24' >24</option><option value = '-1' >Clear</option></Select></B></small></small></TD>
  <TD WIDTH=70 Height=3 nowrap><small><small><B>
Hours     </B></small></small></TD><TD WIDTH=70 Height=3><small><small><B></B></small></small></TD>
            <td WIDTH=100 Height=3><small><small><B><input type="text" name="txt_1_6" value="test1" >
   </B></small></small></TD>
   
<TR align=center><TD Width=90 Height=3 nowrap ><B>2</B></TD><TD Width=90 Height=3 nowrap ><B>1143-01427</B></TD><TD WIDTH=200 Height=3><small><small><B>1143-01427 E450552 TITANIUM SBPR</B></small></small></TD><TD WIDTH=30 Height=3><small><small><B></B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>Load_Cycle</B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>2</B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>LDGS      </B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>LDGC      </B></small></small></TD><TD WIDTH=70 Height=3><B>3</B></TD><TD WIDTH=70 Height=3><small><small><B><Select name = 'DDSQ_2_2' font-size=1><option value = '1' >1</option><option value = '2' >2</option><option value = '3' selected>3</option><option value = '4' >4</option><option value = '5' >5</option><option value = '6' >6</option><option value = '7' >7</option><option value = '8' >8</option><option value = '9' >9</option><option value = '10' >10</option><option value = '11' >11</option><option value = '12' >12</option><option value = '13' >13</option><option value = '14' >14</option><option value = '15' >15</option><option value = '16' >16</option><option value = '17' >17</option><option value = '18' >18</option><option value = '19' >19</option><option value = '20' >20</option><option value = '21' >21</option><option value = '22' >22</option><option value = '23' >23</option><option value = '24' >24</option><option value = '-1' >Clear</option></Select></B></small></small></TD>
  <TD WIDTH=70 Height=3 nowrap><small><small><B>
Hours     </B></small></small></TD><TD WIDTH=70 Height=3><small><small><B></B></small></small></TD>
            <td WIDTH=100 Height=3><small><small><B><input type="text" name="txt_2_2" value="" >
   </B></small></small></TD>
   
<TR align=center><TD Width=90 Height=3 nowrap ><B>2</B></TD><TD Width=90 Height=3 nowrap ><B>1143-01427</B></TD><TD WIDTH=200 Height=3><small><small><B>1143-01427 E450552 TITANIUM SBPR</B></small></small></TD><TD WIDTH=30 Height=3><small><small><B></B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>Test_Cycle</B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>4</B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>TSTS      </B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>TSTC      </B></small></small></TD><TD WIDTH=70 Height=3><B>6</B></TD><TD WIDTH=70 Height=3><small><small><B><Select name = 'DDSQ_2_4' font-size=1><option value = '1' >1</option><option value = '2' >2</option><option value = '3' >3</option><option value = '4' >4</option><option value = '5' >5</option><option value = '6' selected>6</option><option value = '7' >7</option><option value = '8' >8</option><option value = '9' >9</option><option value = '10' >10</option><option value = '11' >11</option><option value = '12' >12</option><option value = '13' >13</option><option value = '14' >14</option><option value = '15' >15</option><option value = '16' >16</option><option value = '17' >17</option><option value = '18' >18</option><option value = '19' >19</option><option value = '20' >20</option><option value = '21' >21</option><option value = '22' >22</option><option value = '23' >23</option><option value = '24' >24</option><option value = '-1' >Clear</option></Select></B></small></small></TD>
  <TD WIDTH=70 Height=3 nowrap><small><small><B>
Hours     </B></small></small></TD><TD WIDTH=70 Height=3><small><small><B></B></small></small></TD>
            <td WIDTH=100 Height=3><small><small><B><input type="text" name="txt_2_4" value="test" >
   </B></small></small></TD>
   
<TR align=center><TD Width=90 Height=3 nowrap ><B>2</B></TD><TD Width=90 Height=3 nowrap ><B>1143-01427</B></TD><TD WIDTH=200 Height=3><small><small><B>1143-01427 E450552 TITANIUM SBPR</B></small></small></TD><TD WIDTH=30 Height=3><small><small><B></B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>FILL_Cycle</B></small></small></TD><TD WIDTH=100 Height=3><small><small><B>6</B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>FLGS      </B></small></small></TD><TD WIDTH=90 Height=3><small><small><B>FLGC      </B></small></small></TD><TD WIDTH=70 Height=3><B>6</B></TD><TD WIDTH=70 Height=3><small><small><B><Select name = 'DDSQ_2_6' font-size=1><option value = '1' >1</option><option value = '2' >2</option><option value = '3' >3</option><option value = '4' >4</option><option value = '5' >5</option><option value = '6' selected>6</option><option value = '7' >7</option><option value = '8' >8</option><option value = '9' >9</option><option value = '10' >10</option><option value = '11' >11</option><option value = '12' >12</option><option value = '13' >13</option><option value = '14' >14</option><option value = '15' >15</option><option value = '16' >16</option><option value = '17' >17</option><option value = '18' >18</option><option value = '19' >19</option><option value = '20' >20</option><option value = '21' >21</option><option value = '22' >22</option><option value = '23' >23</option><option value = '24' >24</option><option value = '-1' >Clear</option></Select></B></small></small></TD>
  <TD WIDTH=70 Height=3 nowrap><small><small><B>
Hours     </B></small></small></TD><TD WIDTH=70 Height=3><small><small><B></B></small></small></TD>
            <td WIDTH=100 Height=3><small><small><B><input type="text" name="txt_2_6" value="test2" >
   </B></small></small></TD>
   


</table>
</form>
</center>

</div>
</div>


<p><small><small><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
End of Report.</strong></small></small></p>

<p align="center"><strong><big><big>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</big></big></strong></p>


</body>
</html>

  document.frmDtls.hfrom.value = 'Updt' ;
          document.frmDtls.method = "post" ;
        document.frmDtls.action = "PRDB_Display_Selected_DUAL_CODE_CYCLE_TIMES_for_UPDATES.asp" ;
          document.frmDtls.submit();
sQry = ""
For Id = 0 to 22
  response.Write ("this is " & l_comments)
  If Trim(sProcess_Step_Sequence (Id)) <> "" Then
    If Trim(sQry) = "" Then
      sQry = sProfile(id) & "~" & sCycleTime(Id) & "`" & sProcess_Step_Sequence(Id) & "^" & sComment(id)
    Else
      sQry = sQry & "!" & sProfile(id) & "~" & sCycleTime(Id) & "`" & sProcess_Step_Sequence(Id)& "^" & sComment(id)
    End If
  End If
Next
objCommand.CommandText = "EXEC usp_UPDATE_Dual_Code_Cycle_Times_and_Comments '" & sQry & "' ; "
Narendra
  • 21
  • 5
  • Possible duplicate of [Using Stored Procedure in Classical ASP .. execute and get results](https://stackoverflow.com/questions/21915874/using-stored-procedure-in-classical-asp-execute-and-get-results) – user692942 Feb 13 '19 at 08:26
  • If you dynamically assign values like that, basically you are negating the whole point of using the `ADODB.Command` object to execute a parameterised query. – user692942 Feb 13 '19 at 08:34
  • This query gets fired after validating from Javascript. I am sending special character concatenated records to database and I have a procedure which splits all that and updates. – Narendra Feb 13 '19 at 08:46
  • Did I just hear you right, Client-side validation? – user692942 Feb 13 '19 at 09:56
  • See my requirement was to update multiple records at once , by clicking Submit button. So on Submit click I have javascript function which is being used to set form's Value, action , method and then Submit. In ASP I have 'for each' loop which is getting Values of all Text boxes and Select boxes. then appending those values to string separated by special characters and finally reading them in the database. Everything is working fine but I want to send only those rows to update where values in the text and select box has changed – Narendra Feb 13 '19 at 10:18
  • By doing so you are completely neglecting the fact you've left yourself wide open to [SQL Injection](https://en.wikipedia.org/wiki/SQL_injection) as you bypass the whole point of a parameterised query. I could inject whatever I liked into that page and likely destroy your database. – user692942 Feb 13 '19 at 11:01
  • 1
    I understand that and that is done by the application owner. I am only asked to pass the values of only those rows where data has been changed. See the link in the question. Can we do that? – Narendra Feb 13 '19 at 11:04
  • If you need to check in the client side for any changes, you will need to use javascript/jquery and the html source of the page will be useful for someone to help. You need to add the javascript, JQuery tags to the question too. ASP has nothing much to do in this case. – Flakes Feb 13 '19 at 11:37
  • 1
    @SearchAndResQ Yes you are right. I have added tags now. The javascript code to check original and changed values and then retrieve changed values is all I am looking for. – Narendra Feb 13 '19 at 12:00
  • The html source for the page will also be needed. – Flakes Feb 13 '19 at 12:06
  • Added the HTML source – Narendra Feb 13 '19 at 13:20

0 Answers0