Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on 

Insert Button on a table

Hi experts, I wish to insert button on a table while on looping. I want a button to be created between Proname and Price. Is it possible? like the code bellow I want to insert this between Proname and Price <td><button class="Addbutton">myButton</button></td>
                           
Set rs = cn.Execute("Select Procode, Proname, Price from Stock")
<table id="myTable" style="cursor: pointer" class="one" Width="100%">
                              <tr class="header1">
                              <th style="width:2%;">Procode</th>
                              <th style="width:90%;">Proname</th>
                              <th style="width:4%;">myButton</th>
                              <th style="width:4%;">Price</th>  
                           </tr>
                           <%do until rs.EOF%>
                              <tr>
                           <%for each x in rs.Fields%>
                              <td><%Response.Write(x.value)%></td>
                           <%next
                                 rs.MoveNext%>
                              </tr>                
                           <%loop                            
                           rs.close
                           cn.close
                           end if
                        %>
                          </table>
CSSHTMLASPJavaScript

Avatar of undefined
Last Comment
Whing Dela Cruz
SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Whing Dela Cruz

ASKER

Hello Monty, The result was that, the button appear alternately to columns 2 on row 1, columns 1 on row 2, Columns 3 on Row 2. What I want here is that the button will permanently resides to columns 3 or between Proname and Price and the value of Procode and Proname shall not be changed. I'm trying to make some adjustment base on your given code but I have no good result.
Avatar of Big Monty
Big Monty
Flag of United States of America image

Ok I'm out at the moment, when I get back I'll get to finish this up today or tomorrow at the latest.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Whing Dela Cruz

ASKER

HI Guys, All solutions are useful and best to me, but i choose heilo's solution. Thanks a lot for your brilliant brain. More power and God bless you all!
Avatar of Whing Dela Cruz

ASKER

Hi Julian, If you don't mind, I wish to use your solution given above but I'm having error says, "Syntax error." This is your code from above solution. Thank you!

<td><%Response.Write(rs('Procode')%>)</td>
Avatar of hielo
hielo
Flag of Wallis and Futuna image

>> 'Procode'
In VBScript, you use an apostrophe as a line comment, so you need to change the apostrophes to double quotes:
<td><%Response.Write(rs("Procode")%>)</td>
Avatar of Whing Dela Cruz

ASKER

Hi hielo, i changed it to this, <td><%Response.Write(rs("Procode"))%></td>  but an error says,

Error Type:
Response object, ASP 0104 (0x80070057)
Operation not Allowed
/Index1.asp
Avatar of Whing Dela Cruz

ASKER

I also tried to use this code below and I've got the same error

                           <table id="myTable" style="cursor: pointer" class="one" Width="100%">
                           <%do until rs.EOF%>
                              <tr>
                                 <td><button class="Addbutton">myButton</button></td>
                              </tr>
                             
                           <%loop
Avatar of hielo
hielo
Flag of Wallis and Futuna image

On your original post you have:
Set rs = cn.Execute("Select Procode, Proname, Price from Stock")
<table id="myTable" style="cursor: pointer" class="one" Width="100%">

Open in new window


You are missing a %> between those lines:
Set rs = cn.Execute("Select Procode, Proname, Price from Stock")
%>
<table id="myTable" style="cursor: pointer" class="one" Width="100%">

Open in new window

Also, on your last post you are not calling rs.MoveNext.  

Set rs = cn.Execute("Select Procode, Proname, Price from Stock")
%>
<table id="myTable" style="cursor: pointer" class="one" Width="100%">
	<tr class="header1">
		<th style="width:2%;">Procode</th>
		<th style="width:90%;">Proname</th>
		<th style="width:4%;">myButton</th>
		<th style="width:4%;">Price</th>  
	</tr>
	<%do until rs.EOF%>
	<tr>
		<td><%Response.Write(rs("Procode")%>)</td>
		<td><%Response.Write(rs("Proname"))%></td>
		<td><button class="Addbutton">myButton</button></td>
		<td><%Response.Write(rs("Price"))%></td>
	</tr>
<%
            rs.MoveNext
	   loop                            
	rs.close
	cn.close
%>
</table> 

Open in new window


If the problems persist, post the code you are actually using now.
Avatar of Whing Dela Cruz

ASKER

Hi Heilo, This are the codes..
               <div id="Win" class="my-overflow">
                        <%
                           dim cn, rs
                           Set cn = Server.CreateObject("ADODB.Connection")
                           Set rs = Server.CreateObject("ADODB.Recordset")
                           cn.ConnectionString = "driver={SQL Server};server=MYSERVER;uid=;pwd=;database=MyDB"
                           cn.Open
                           Set rs = cn.Execute("Select Proname, Procode from STOCK")
                        %>
                           <table id="myTable" style="cursor: pointer" class="one" Width="100%">
                           <%do until rs.EOF%>
                              <tr>
                                 <td><button class=""Addbutton"" onclick=""return iFunction()"">Add</button></td>
                                 <td><%Response.Write(rs("Procode"))%></td>
                                 <td><%Response.Write(rs("Proname"))%></td>
                              </tr>
                           <%loop
                           rs.close
                           cn.close
                        %>
                          </table>
               </div>
Avatar of Big Monty
Big Monty
Flag of United States of America image

<%do until rs.EOF%>
      <tr>
     <td><button class=""Addbutton"" onclick=""return iFunction()"">Add</button></td>
     <td><%Response.Write(rs("Procode"))%></td>
    <td><%Response.Write(rs("Proname"))%></td>
   </tr>
   <%loop
     ......

    should be:

 <%do until rs.EOF%>
      <tr>
     <td><button class=""Addbutton"" onclick=""return iFunction()"">Add</button></td>
     <td><%Response.Write(rs("Procode"))%></td>
    <td><%Response.Write(rs("Proname"))%></td>
   </tr>
       <%rs.MoveNext
    loop
     ......
Avatar of hielo
hielo
Flag of Wallis and Futuna image

>> <td><button class=""Addbutton"" onclick=""return iFunction()"">Add</button></td>
You need the back-to-back double quotes only if you are within a VBScript block emitting a string -- like the Response.Write() that you were using earlier for that particular line.  The way it is now, the onclick will not work.  What you need is:
<div id="Win" class="my-overflow">
                        <%
                           dim cn, rs
                           Set cn = Server.CreateObject("ADODB.Connection")
                           Set rs = Server.CreateObject("ADODB.Recordset")
                           cn.ConnectionString = "driver={SQL Server};server=MYSERVER;uid=;pwd=;database=MyDB"
                           cn.Open
                           Set rs = cn.Execute("Select Proname, Procode from STOCK")
                        %>
                           <table id="myTable" style="cursor: pointer" class="one" Width="100%">
                           <%do until rs.EOF%>
                              <tr>
                                 <td><button class="Addbutton" onclick="return iFunction()">Add</button></td>
                                 <td><%Response.Write(rs("Procode"))%></td>
                                 <td><%Response.Write(rs("Proname"))%></td>
                              </tr>
                           <%
                           rs.MoveNext
                           Loop
                           rs.close
                           cn.close
                        %>
                          </table>
               </div>

Open in new window

Avatar of Whing Dela Cruz

ASKER

You are right hielo, onclick is now working properly. Thank for your great knowledge. Your different ideas and techniques helps me a lot doing my project. I can't give you points on this great answered but one thing that I would like to say to both of guys is Great Job! More power to both of you and God bless you all!
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo