473,836 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically changing the Button initial

100 New Member
Hi,
I have an asp code which creates a grid or matrics (5 x 5 matrics).Each cell contains a button which will have an initial
.The initial will be read from a database.

say the database has these entries...table name is "TestSuite"
---------- ------- --------
| Initial | Name |
---------- ------- --------
| S | TestSuite1 |
-------------------------------
| R | Suite2
-------------------------------
|G | Suite3
-------------------------------
| T | Suite4
-------------------------------


Initially the button should contain "S" or the first entry of the database and on clicking the button it should change to the next initial say "R".

On clicking the button it should keep changing to the next entry till the last and again from first.


How can i do??...With javascript function??....E arlier i had a combo box which had all the initial in it.User had an option to select a particular "Initial'....Ca n any one please help me in having a dynamic button??....
Feb 5 '08 #1
1 1285
CroCrew
564 Recognized Expert Contributor
Hello rag84dec,

Looking at your question, if it were me I would do it with client side scripting so I would not have to refresh the page on every click of the button. Here is an example that you could use. The code is using Microsoft Access because you did not specify what database you are using. Let me know if I need to explain in detail what is going on in the page, I will be happy to do so.

Hope this helps~

Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Set Conn = Server.CreateObject("ADODB.Connection")
  3.         Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Relative path to your Access database") 
  4.  
  5.     Set MyRS = Server.CreateObject("ADODB.Recordset") 
  6.         SQL = "SELECT * FROM TheTable"
  7.         MyRS.CursorType = 1
  8.         MyRS.LockType = 3
  9.         MyRS.Open SQL, Conn
  10.  
  11.     Do Until (MyRS.EOF)
  12.         i=(i+1)
  13.         If (MyRS.RecordCount => (i+1)) Then
  14.             TempButtonArray = TempButtonArray & "'" & MyRS("FieldOne") & "', "
  15.         Else
  16.             TempButtonArray = TempButtonArray & "'" & MyRS("FieldOne") & "'"
  17.         End If
  18.         MyRS.MoveNext
  19.     Loop
  20.  
  21.     MyRS.close
  22.     Conn.close
  23. %>
  24. <html>
  25.     <head>
  26.         <title>Example</title>
  27.         <script language="JavaScript">
  28.             var dbButtonArray = new Array(<%=TempButtonArray%>);
  29.             var CurrentButtonValue = 0;
  30.             function ChangeButton()
  31.             {
  32.                 if (CurrentButtonValue == (dbButtonArray.length-1))
  33.                 {
  34.                     CurrentButtonValue = 0;
  35.                 }
  36.                 else
  37.                 {
  38.                     CurrentButtonValue = (CurrentButtonValue + 1);
  39.                 }
  40.                 document.xform.xButton.value=dbButtonArray[CurrentButtonValue];
  41.             }
  42.         </script>
  43.     </head>
  44.     <body>
  45.         <form method="post" action="Post_Update.asp" name="xform">
  46.             <input type="button" name="xButton" value="Click Me" onclick="ChangeButton();">
  47.         </form>
  48.     </body>
  49.     <script language="JavaScript">document.xform.xButton.value=dbButtonArray[0];</script>
  50. </html>
  51.  
Feb 5 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
2206
by: Randy Webb | last post by:
This page: http://www.hikksworld.com/loadJSFiles/ Is one where I was testing the ability of browsers that can/can't dynamically load a JS file with one of the three methods: 1)Changing the src property of a script tag. 2)Inserting a script src="" tag in a div via innerHTML 3)Using document.createElement to add a script element. The fourth method on the page is writing a script tag to a layer, and to the best of my knowledge it only...
2
18585
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } Which is called statically by: <button onclick="doClick(event,this);">Click me</button>
5
14553
by: Good Man | last post by:
Hi there I'm adding form fields on the fly with some javascript DOM programming. I basically just clone a hidden <div>, then adjust node properties to make this new <div> have unique values (style, size, etc.) the original code of the input tag is: <input type="file" onchange="alert('original')" size="30" id="filea" name="filea">
1
8583
by: Paul M. Frazier, Ph.D. | last post by:
I am writing a user information update page and I populate the form on Page_Load with the current values of the user's name, etc. When I change the text in one of the textbox controls (e.g., change the user's middle initial from M. to X.) and submit the form, the value seen for middleinitial.text in the Public Sub that is executed when the Update button is clicked is the initial value (M.) and not the new value (X.). Is there something I...
1
8187
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
10
2720
by: Jess | last post by:
Hello, I have a program that stores dynamically created objects into a vector. #include<iostream> #include<vector> using namespace std;
7
6680
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a tabcontainer which has 1 panel already, however I want to try create the TabPanels dynamically. I followed the advice here: http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe Stagner)
3
5283
by: Allen Chen [MSFT] | last post by:
Hi Richard, Quote from Richard================================================== However I also want to be able to remove the panes. I have tried to include this, but find that when I first add the pane the remove event does not get handled, though thereafter it is handled without problems. ==================================================
1
1584
by: deegeorge | last post by:
Hi, we have designed an online shopping website.in that we r displaying the online products for all the products we hve a buy button and details button which is created dynamically on click of details buttons we r showing a window which is also created dynamically.actually the window is a panel and we r dynamically changing the content inside the panel for ecah product my problem is that nw if i click on the details button it is comin...
0
9818
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6978
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5648
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4015
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3112
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.