Link to home
Start Free TrialLog in
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>
SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
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>
>> '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>
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
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
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.
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>
<%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
     ......
>> <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

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!